Skip to content

Commit 33315ea

Browse files
committed
stronger types and php 8 methods
1 parent 110164c commit 33315ea

File tree

4 files changed

+11
-17
lines changed

4 files changed

+11
-17
lines changed

src/Util/AutoloaderUtil.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ public function getPathForFutureClass(string $className): ?string
3636

3737
// lookup is obviously modeled off of Composer's autoload logic
3838
foreach ($classLoader->getPrefixesPsr4() as $prefix => $paths) {
39-
if (0 === strpos($className, $prefix)) {
39+
if (str_starts_with($className, $prefix)) {
4040
return $paths[0].'/'.str_replace('\\', '/', substr($className, \strlen($prefix))).'.php';
4141
}
4242
}
4343

4444
foreach ($classLoader->getPrefixes() as $prefix => $paths) {
45-
if (0 === strpos($className, $prefix)) {
45+
if (str_starts_with($className, $prefix)) {
4646
return $paths[0].'/'.str_replace('\\', '/', $className).'.php';
4747
}
4848
}
@@ -61,7 +61,7 @@ public function getPathForFutureClass(string $className): ?string
6161
public function getNamespacePrefixForClass(string $className): string
6262
{
6363
foreach ($this->getClassLoader()->getPrefixesPsr4() as $prefix => $paths) {
64-
if (0 === strpos($className, $prefix)) {
64+
if (str_starts_with($className, $prefix)) {
6565
return $prefix;
6666
}
6767
}
@@ -78,7 +78,7 @@ public function isNamespaceConfiguredToAutoload(string $namespace): bool
7878
$classLoader = $this->getClassLoader();
7979

8080
foreach ($classLoader->getPrefixesPsr4() as $prefix => $paths) {
81-
if (0 === strpos($namespace, $prefix)) {
81+
if (str_starts_with($namespace, $prefix)) {
8282
return true;
8383
}
8484
}

src/Util/ClassDetails.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,6 @@ public function doesDocBlockContainAnnotation(string $annotation): bool
7070
return false;
7171
}
7272

73-
return false !== strpos($docComment, $annotation);
73+
return str_contains($docComment, $annotation);
7474
}
7575
}

src/Util/ComposerAutoloaderFinder.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,8 @@
2020
*/
2121
class ComposerAutoloaderFinder
2222
{
23-
private $rootNamespace;
24-
25-
/**
26-
* @var ClassLoader|null
27-
*/
28-
private $classLoader = null;
23+
private array $rootNamespace;
24+
private ?ClassLoader $classLoader = null;
2925

3026
public function __construct(string $rootNamespace)
3127
{
@@ -96,13 +92,13 @@ private function locateMatchingClassLoader(ClassLoader $classLoader): ?ClassLoad
9692
if ('Symfony\\Bundle\\MakerBundle\\' === $prefix) {
9793
$makerClassLoader = $classLoader;
9894
}
99-
if (0 === strpos($this->rootNamespace['psr4'], $prefix)) {
95+
if (str_starts_with($this->rootNamespace['psr4'], $prefix)) {
10096
return $classLoader;
10197
}
10298
}
10399

104100
foreach ($classLoader->getPrefixes() as $prefix => $paths) {
105-
if (0 === strpos($this->rootNamespace['psr0'], $prefix)) {
101+
if (str_starts_with($this->rootNamespace['psr0'], $prefix)) {
106102
return $classLoader;
107103
}
108104
}

src/Util/MakerFileLinkFormatter.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,10 @@
1919
*/
2020
final class MakerFileLinkFormatter
2121
{
22-
private $fileLinkFormatter;
23-
24-
public function __construct(FileLinkFormatter $fileLinkFormatter = null)
22+
public function __construct(private ?FileLinkFormatter $fileLinkFormatter = null)
2523
{
2624
// Since nullable types are not available in 7.0; can be removed when php >= 7.1 required
27-
if (0 == \func_num_args()) {
25+
if (0 === \func_num_args()) {
2826
throw new \LogicException('$fileLinkFormatter argument is required');
2927
}
3028

0 commit comments

Comments
 (0)