diff --git a/src/StaticAnalysis/CodeUnitFindingVisitor.php b/src/StaticAnalysis/CodeUnitFindingVisitor.php index 6c8a5792a..dbb81d597 100644 --- a/src/StaticAnalysis/CodeUnitFindingVisitor.php +++ b/src/StaticAnalysis/CodeUnitFindingVisitor.php @@ -10,7 +10,6 @@ namespace SebastianBergmann\CodeCoverage\StaticAnalysis; use function implode; -use function str_replace; use function trim; use PhpParser\Node; use PhpParser\Node\Identifier; @@ -285,13 +284,6 @@ private function processFunction(Function_ $node): void private function namespace(string $namespacedName, string $name): string { - return trim( - str_replace( - $name, - '', - $namespacedName - ), - '\\' - ); + return trim(rtrim($namespacedName, $name), '\\'); } } diff --git a/tests/_files/ClassThatUsesAnonymousClass.php b/tests/_files/ClassThatUsesAnonymousClass.php index d3a8a964c..20ebe09fd 100644 --- a/tests/_files/ClassThatUsesAnonymousClass.php +++ b/tests/_files/ClassThatUsesAnonymousClass.php @@ -1,5 +1,5 @@ assertSame('ClassThatUsesAnonymousClass', $class['name']); $this->assertSame(ClassThatUsesAnonymousClass::class, $class['namespacedName']); - $this->assertSame('SebastianBergmann\CodeCoverage\TestFixture', $class['namespace']); + $this->assertSame('SebastianBergmann\CodeCoverage\ClassThatUsesAnonymousClass\TestFixture', $class['namespace']); $this->assertSame(4, $class['startLine']); $this->assertSame(17, $class['endLine']);