Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

StringClassReference - fixed regular expression to match FQCN #14

Merged
merged 1 commit into from
May 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"';