diff --git a/src/Selector/ClassNamespace.php b/src/Selector/ClassNamespace.php index 419a0e7b..f82c3783 100644 --- a/src/Selector/ClassNamespace.php +++ b/src/Selector/ClassNamespace.php @@ -28,7 +28,7 @@ public function matches(ClassReflection $classReflection): bool return $this->matchesRegex($namespace); } - return str_starts_with(\trimSeparators($namespace), \trimSeparators($this->namespace)); + return str_starts_with(\trimSeparators($namespace).'\\', \trimSeparators($this->namespace).'\\'); } private function matchesRegex(string $namespace): bool diff --git a/tests/fixtures/FixtureClass.php b/tests/fixtures/FixtureClass.php index 7873b7e0..fc2efdb8 100644 --- a/tests/fixtures/FixtureClass.php +++ b/tests/fixtures/FixtureClass.php @@ -60,13 +60,13 @@ public function usingStaticMethod(): void } /** - * @param SimpleClass $p - * @param SimpleClassTwo $p2 Parameter with description - * @param \Tests\PHPat\fixtures\Simple\SimpleClassThree $p3 - * @param array $p4 - * @param SimpleClassFive|SimpleClassSix $p5_6 - * @param InterfaceWithTemplate $t - * @return SimpleInterface Some nice description here + * @param SimpleClass $p + * @param SimpleClassTwo $p2 Parameter with description + * @param SimpleClassThree $p3 + * @param array $p4 + * @param SimpleClassFive|SimpleClassSix $p5_6 + * @param InterfaceWithTemplate $t + * @return SimpleInterface Some nice description here * @throws SimpleException */ public function methodWithDocBlocks($p, $p2, $p3, $p4, $p5_6, $t) diff --git a/tests/fixtures/Ns/Foo/ClassUnderFooNamespace.php b/tests/fixtures/Ns/Foo/ClassUnderFooNamespace.php new file mode 100644 index 00000000..3885a669 --- /dev/null +++ b/tests/fixtures/Ns/Foo/ClassUnderFooNamespace.php @@ -0,0 +1,5 @@ + + * @internal + * @coversNothing + */ +class ClassnamespaceTest extends RuleTestCase +{ + public const RULE_NAME = 'test_FixtureClassUnderNamespaceShouldBeNamed'; + + public function testRule(): void + { + // Class under FooBar should not subject to the rule + $this->analyse(['tests/fixtures/Ns/FooBar/ClassUnderFooBarNamespace.php'], []); + } + + protected function getRule(): Rule + { + $testParser = FakeTestParser::create( + self::RULE_NAME, + ShouldBeNamed::class, + [new ClassNamespace('Tests\PHPat\fixtures\Ns\Foo', false)], + [], + [], + ['isRegex' => false, 'classname' => ClassUnderFooNamespace::class] + ); + + return new ClassnameRule( + new StatementBuilderFactory($testParser), + new Configuration(false, true, false), + $this->createReflectionProvider(), + self::getContainer()->getByType(FileTypeMapper::class) + ); + } +}