Skip to content

Commit fad4fde

Browse files
przepompownia__
andauthored
ClassName::fromString(): trim leading namespace separator (#32)
* `ClassName::fromString()`: trim leading namespace separator * CI: bump PHP version to 8.1 * Cast to string --------- Co-authored-by: __ <__@__>
1 parent 290dabd commit fad4fde

File tree

5 files changed

+19
-6
lines changed

5 files changed

+19
-6
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
strategy:
2020
matrix:
2121
php-version:
22-
- '7.4'
22+
- '8.1'
2323

2424
steps:
2525
-
@@ -52,7 +52,7 @@ jobs:
5252
strategy:
5353
matrix:
5454
php-version:
55-
- '7.4'
55+
- '8.1'
5656

5757
steps:
5858
-
@@ -85,8 +85,7 @@ jobs:
8585
strategy:
8686
matrix:
8787
php-version:
88-
- '7.4'
89-
- '8.0'
88+
- '8.1'
9089

9190
steps:
9291
-

lib/Adapter/Composer/ComposerClassToFile.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function classToFileCandidates(ClassName $className): FilePathCandidates
3131

3232
// order with the longest prefixes first
3333
uksort($candidates, function ($prefix1, $prefix2) {
34-
return strlen($prefix2) <=> strlen($prefix1);
34+
return strlen((string)$prefix2) <=> strlen((string)$prefix1);
3535
});
3636

3737
// flatten to a single array

lib/Domain/ClassName.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public function __toString()
2222
public static function fromString(string $string): self
2323
{
2424
$new = new self();
25-
$new->fullyQualifiedName = $string;
25+
$new->fullyQualifiedName = ltrim($string, self::DEFAULT_NAMESPACE_SEPARATOR);
2626

2727
return $new;
2828
}

tests/Integration/Simple/SimpleClassToFileTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,15 @@ public function testClassToFile(): void
3030
]), $candidates);
3131
}
3232

33+
public function testAbsoluteClassNameToFile(): void
34+
{
35+
$candidates = $this->classToFile->classToFileCandidates(ClassName::fromString('\\Acme\\Foobar'));
36+
37+
$this->assertEquals(FilePathCandidates::fromFilePaths([
38+
FilePath::fromString(__DIR__ . '/../../Workspace/lib/Foobar.php')
39+
]), $candidates);
40+
}
41+
3342
public function testClassToFileInvalid(): void
3443
{
3544
$candidates = $this->classToFile->classToFileCandidates(

tests/Unit/ClassNameTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ public function provideBeginsWith()
2424
'Foobar',
2525
true,
2626
],
27+
[
28+
'\\Foobar\\BarFoo',
29+
'Foobar\\BarFoo',
30+
true,
31+
],
2732
[
2833
'Foobar\\BarFoo',
2934
'Foobar\\BarFoo',

0 commit comments

Comments
 (0)