Skip to content
Snippets Groups Projects
Unverified Commit e79554be authored by Jonathan Smith's avatar Jonathan Smith Committed by GitHub
Browse files

fix(ConstantName): Fix constant name detection with define() calls (#3369978 by jonathan1055)

parent 88055e40
No related branches found
No related tags found
No related merge requests found
......@@ -117,7 +117,8 @@ class ConstantNameSniff implements Sniff
return;
}
$constName = $tokens[$constPtr]['content'];
// Get the constant name and remove single and double quotes.
$constName = str_replace(["'", '"'], ['', ''], $tokens[$constPtr]['content']);
if (strpos($constName, $expectedStart) !== 0) {
$warning = 'All constants defined by a module must be prefixed with the module\'s name, expected "%s" but found "%s"';
......
......@@ -54,9 +54,11 @@ class ConstantNameUnitTest extends CoderSniffUnitTest
*/
protected function getWarningList(string $testFile): array
{
// The .install and .module test files are identical, so the return
// array can be the same, without checking $testFile.
return [
3 => 1,
5 => 1,
6 => 1,
];
}//end getWarningList()
......
<?php
define('WRONG_CONSTANT_NAME', 'test');
define('CONSTANT_TEST_OK', 'test');
const ANOTHER_WRONG_NAME = 'test';
const CONSTANT_TEST_NAME_OK = 'test';
class Test {
const CLASS_CONSTANT = 'should be ignored';
......
<?php
define('WRONG_CONSTANT_NAME', 'test');
define('CONSTANT_TEST_OK', 'test');
const ANOTHER_WRONG_NAME = 'test';
const CONSTANT_TEST_NAME_OK = 'test';
class Test {
const CLASS_CONSTANT = 'should be ignored';
......
<?php
/**
* @file
* This file contains valid notations for the drupal coding standard.
*
* It is used to check sniffs that run on .module files but skip .php files.
*/
define('GOOD_FOO_BAR', 5);
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment