Skip to content

Commit 015f40c

Browse files
committed
Update src/Fixer/StringableInterfaceFixer.php
1 parent db3b752 commit 015f40c

File tree

1 file changed

+13
-15
lines changed

1 file changed

+13
-15
lines changed

src/Fixer/StringableInterfaceFixer.php

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public function fix(\SplFileInfo $file, Tokens $tokens): void
7373
}
7474

7575
if ($tokens[$index]->isGivenKind(\T_USE)) {
76-
$name = self::getNameFromUse($tokens, $index, $useDeclarations);
76+
$name = self::getNameFromUse($index, $useDeclarations);
7777
if ($name !== null) {
7878
$stringableInterfaces[] = $name;
7979
}
@@ -101,25 +101,23 @@ public function fix(\SplFileInfo $file, Tokens $tokens): void
101101
}
102102
}
103103

104-
/**
105-
* @param list<NamespaceUseAnalysis> $useDeclarations
106-
*/
107-
private static function getNameFromUse(Tokens $tokens, int $index, array $useDeclarations): ?string
104+
private static function getNameFromUse(int $index, array $useDeclarations): ?string
108105
{
109-
foreach ($useDeclarations as $useDeclaration) {
110-
if ($useDeclaration->getStartIndex() !== $index) {
111-
continue;
112-
}
106+
$uses = \array_filter(
107+
$useDeclarations,
108+
static fn (NamespaceUseAnalysis $namespaceUseAnalysis): bool => $namespaceUseAnalysis->getStartIndex() === $index,
109+
);
113110

114-
$lowercasedFullName = \strtolower($useDeclaration->getFullName());
115-
if ($lowercasedFullName !== 'stringable' && $lowercasedFullName !== '\\stringable') {
116-
return null;
117-
}
111+
\assert(\count($uses) === 1);
112+
113+
$useDeclaration = \reset($uses);
118114

119-
return \strtolower($useDeclaration->getShortName());
115+
$lowercasedFullName = \strtolower($useDeclaration->getFullName());
116+
if ($lowercasedFullName !== 'stringable' && $lowercasedFullName !== '\\stringable') {
117+
return null;
120118
}
121119

122-
return null;
120+
return \strtolower($useDeclaration->getShortName());
123121
}
124122

125123
private static function doesHaveToStringMethod(Tokens $tokens, int $classStartIndex, int $classEndIndex): bool

0 commit comments

Comments
 (0)