Skip to content

Commit

Permalink
StringClassReference - fixed regular expression to match FQCN
Browse files Browse the repository at this point in the history
  • Loading branch information
michalbundyra committed May 11, 2019
1 parent 4367f51 commit bee9f9f
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,8 @@ public function process(File $phpcsFile, $stackPtr)
return;
}

$name = strtr($tokens[$stackPtr]['content'], [
'"' => '',
"'" => '',
'\\\\' => '\\',
]);

if (strpos($name, '\\\\') !== false
|| preg_match('/[^\\a-zA-Z_\x80-\xff][a-zA-Z0-9_\x80-\xff]/', $name)
|| substr($name, -1) === '\\'
|| ltrim($name, '\\') === ''
) {
$name = substr(str_replace('\\\\', '\\', $tokens[$stackPtr]['content']), 1, -1);
if (! preg_match('/^(\\\\?[a-zA-Z_\x80-\xff][a-zA-Z0-9_\x80-\xff]*)+$/', $name)) {
return;
}

Expand Down
2 changes: 2 additions & 0 deletions test/Sniffs/Formatting/StringClassReferenceUnitTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,5 @@ $spaceAtTheEnd = ' WebimpressCodingStandardTest\\Ruleset ';

$namespaceSeparatorAtTheEnd = 'WebimpressCodingStandardTest\\Ruleset\\';
$justNamespaceSeparator = '\\';

$quotes = '"\DateTime"';
2 changes: 2 additions & 0 deletions test/Sniffs/Formatting/StringClassReferenceUnitTest.inc.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,5 @@ $spaceAtTheEnd = ' WebimpressCodingStandardTest\\Ruleset ';

$namespaceSeparatorAtTheEnd = 'WebimpressCodingStandardTest\\Ruleset\\';
$justNamespaceSeparator = '\\';

$quotes = '"\DateTime"';

0 comments on commit bee9f9f

Please sign in to comment.