diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6594e5d7..457d8a11 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,7 +19,7 @@ jobs: strategy: matrix: php-version: - - '7.4' + - '8.1' steps: - @@ -52,7 +52,7 @@ jobs: strategy: matrix: php-version: - - '7.4' + - '8.1' steps: - @@ -85,8 +85,7 @@ jobs: strategy: matrix: php-version: - - '7.4' - - '8.0' + - '8.1' steps: - diff --git a/lib/Adapter/Composer/ComposerClassToFile.php b/lib/Adapter/Composer/ComposerClassToFile.php index 96ca8333..8f4c7478 100644 --- a/lib/Adapter/Composer/ComposerClassToFile.php +++ b/lib/Adapter/Composer/ComposerClassToFile.php @@ -31,7 +31,7 @@ public function classToFileCandidates(ClassName $className): FilePathCandidates // order with the longest prefixes first uksort($candidates, function ($prefix1, $prefix2) { - return strlen($prefix2) <=> strlen($prefix1); + return strlen((string)$prefix2) <=> strlen((string)$prefix1); }); // flatten to a single array diff --git a/lib/Domain/ClassName.php b/lib/Domain/ClassName.php index b1e37aee..1d55e1e2 100644 --- a/lib/Domain/ClassName.php +++ b/lib/Domain/ClassName.php @@ -22,7 +22,7 @@ public function __toString() public static function fromString(string $string): self { $new = new self(); - $new->fullyQualifiedName = $string; + $new->fullyQualifiedName = ltrim($string, self::DEFAULT_NAMESPACE_SEPARATOR); return $new; } diff --git a/tests/Integration/Simple/SimpleClassToFileTest.php b/tests/Integration/Simple/SimpleClassToFileTest.php index a3b07381..6f5922e1 100644 --- a/tests/Integration/Simple/SimpleClassToFileTest.php +++ b/tests/Integration/Simple/SimpleClassToFileTest.php @@ -30,6 +30,15 @@ public function testClassToFile(): void ]), $candidates); } + public function testAbsoluteClassNameToFile(): void + { + $candidates = $this->classToFile->classToFileCandidates(ClassName::fromString('\\Acme\\Foobar')); + + $this->assertEquals(FilePathCandidates::fromFilePaths([ + FilePath::fromString(__DIR__ . '/../../Workspace/lib/Foobar.php') + ]), $candidates); + } + public function testClassToFileInvalid(): void { $candidates = $this->classToFile->classToFileCandidates( diff --git a/tests/Unit/ClassNameTest.php b/tests/Unit/ClassNameTest.php index 6d85ddc4..e9eed364 100644 --- a/tests/Unit/ClassNameTest.php +++ b/tests/Unit/ClassNameTest.php @@ -24,6 +24,11 @@ public function provideBeginsWith() 'Foobar', true, ], + [ + '\\Foobar\\BarFoo', + 'Foobar\\BarFoo', + true, + ], [ 'Foobar\\BarFoo', 'Foobar\\BarFoo',