Skip to content

Commit b1b3fd0

Browse files
committed
Fix aliased use statements leading to problem with classes called like keywords, fixes #9
1 parent 61804f9 commit b1b3fd0

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

src/PhpFileParser.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ public static function findClasses(string $path): array
6363

6464
Preg::matchAll('{
6565
(?:
66-
\b(?<![\$:>])(?P<type>class|interface|trait'.$extraTypes.') \s++ (?P<name>[a-zA-Z_\x7f-\xff:][a-zA-Z0-9_\x7f-\xff:\-]*+)
67-
| \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*+ [\{;]
66+
\b(?<![\\\\$:>])(?P<type>class|interface|trait'.$extraTypes.') \s++ (?P<name>[a-zA-Z_\x7f-\xff:][a-zA-Z0-9_\x7f-\xff:\-]*+)
67+
| \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*+ [\{;]
6868
)
6969
}ix', $contents, $matches);
7070

tests/Fixtures/psrViolations/ClassWithCorrectNameSpace.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@
22

33
namespace ExpectedNamespace;
44

5+
use Foo\Baz\Enum as Bar;
6+
57
class ClassWithCorrectNameSpace {}

tests/Fixtures/psrViolations/ClassWithIncorrectSubNamespace.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@
22

33
namespace ExpectedNamespace\UnexpectedSubNamespace;
44

5-
class ClassWithIncorrectSubNamespace {}
5+
use Foo\Baz\Enum as Bar;
6+
7+
CLass ClassWithIncorrectSubNamespace {}

0 commit comments

Comments
 (0)