diff --git a/src/Component/legacy/tests/Dummy/DummyClassWithDocBlock.php b/src/Component/legacy/tests/Dummy/DummyClassWithDocBlock.php new file mode 100644 index 000000000..0a119d1c5 --- /dev/null +++ b/src/Component/legacy/tests/Dummy/DummyClassWithDocBlock.php @@ -0,0 +1,21 @@ +assertContains(DummyClassOne::class, $resources); $this->assertContains(DummyClassTwo::class, $resources); } + /** @test */ + public function it_excludes_docblock_comments(): void + { + $resources = iterator_to_array(ClassReflection::getResourcesByPath(__DIR__ . '/../Dummy')); + + $this->assertContains(DummyClassWithDocBlock::class, $resources); + $this->assertNotContains('This docblock for this class explains what to do', $resources); + } + /** @test */ public function it_excludes_traits(): void { - $resources = ClassReflection::getResourcesByPath(__DIR__ . '/../Dummy'); + $resources = iterator_to_array(ClassReflection::getResourcesByPath(__DIR__ . '/../Dummy')); $this->assertNotContains(TraitPass::class, $resources); } diff --git a/src/Component/src/Reflection/ClassReflection.php b/src/Component/src/Reflection/ClassReflection.php index 025caf287..5af2b9e18 100644 --- a/src/Component/src/Reflection/ClassReflection.php +++ b/src/Component/src/Reflection/ClassReflection.php @@ -46,7 +46,7 @@ public static function getResourcesByPath(string $path): iterable $namespace = $matches[1] ?? null; - if (!preg_match('/class\s+(\w+)/', $fileContent, $matches)) { + if (!preg_match('/^(?:\s*(?:final|abstract|readonly)\s+)*class\s+(\w+)/mi', $fileContent, $matches)) { // no class found continue; }