Skip to content

Commit

Permalink
Merge pull request #14 from webimpress/hotfix/string-class-reference-…
Browse files Browse the repository at this point in the history
…class-reg-exp

StringClassReference - fixed regular expression to match FQCN
  • Loading branch information
michalbundyra committed May 12, 2019
2 parents 4367f51 + d373f8d commit 629d20e
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 629d20e

Please sign in to comment.