Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ClassName::fromString(): trim leading namespace separator #32

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
strategy:
matrix:
php-version:
- '7.4'
- '8.1'

steps:
-
Expand Down Expand Up @@ -52,7 +52,7 @@ jobs:
strategy:
matrix:
php-version:
- '7.4'
- '8.1'

steps:
-
Expand Down Expand Up @@ -85,8 +85,7 @@ jobs:
strategy:
matrix:
php-version:
- '7.4'
- '8.0'
- '8.1'

steps:
-
Expand Down
2 changes: 1 addition & 1 deletion lib/Adapter/Composer/ComposerClassToFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/Domain/ClassName.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
9 changes: 9 additions & 0 deletions tests/Integration/Simple/SimpleClassToFileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
5 changes: 5 additions & 0 deletions tests/Unit/ClassNameTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ public function provideBeginsWith()
'Foobar',
true,
],
[
'\\Foobar\\BarFoo',
'Foobar\\BarFoo',
true,
],
[
'Foobar\\BarFoo',
'Foobar\\BarFoo',
Expand Down
Loading