Skip to content

Commit

Permalink
Fix aliased use statements leading to problem with classes called lik…
Browse files Browse the repository at this point in the history
…e keywords, fixes #9
  • Loading branch information
Seldaek committed Jun 12, 2024
1 parent 61804f9 commit b1b3fd0
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/PhpFileParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ public static function findClasses(string $path): array

Preg::matchAll('{
(?:
\b(?<![\$:>])(?P<type>class|interface|trait'.$extraTypes.') \s++ (?P<name>[a-zA-Z_\x7f-\xff:][a-zA-Z0-9_\x7f-\xff:\-]*+)
| \b(?<![\$:>])(?P<ns>namespace) (?P<nsname>\s++[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*+(?:\s*+\\\\\s*+[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*+)*+)? \s*+ [\{;]
\b(?<![\\\\$:>])(?P<type>class|interface|trait'.$extraTypes.') \s++ (?P<name>[a-zA-Z_\x7f-\xff:][a-zA-Z0-9_\x7f-\xff:\-]*+)
| \b(?<![\\\\$:>])(?P<ns>namespace) (?P<nsname>\s++[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*+(?:\s*+\\\\\s*+[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*+)*+)? \s*+ [\{;]
)
}ix', $contents, $matches);

Expand Down
2 changes: 2 additions & 0 deletions tests/Fixtures/psrViolations/ClassWithCorrectNameSpace.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@

namespace ExpectedNamespace;

use Foo\Baz\Enum as Bar;

class ClassWithCorrectNameSpace {}
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@

namespace ExpectedNamespace\UnexpectedSubNamespace;

class ClassWithIncorrectSubNamespace {}
use Foo\Baz\Enum as Bar;

CLass ClassWithIncorrectSubNamespace {}

0 comments on commit b1b3fd0

Please sign in to comment.