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 12, 2019
1 parent 4367f51 commit d373f8d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
use function interface_exists;
use function ltrim;
use function preg_match;
use function str_replace;
use function strpos;
use function strtr;
use function substr;
use function trait_exists;

Expand All @@ -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 d373f8d

Please sign in to comment.