Skip to content

Commit

Permalink
[PostRector] Improve UseNodesToAddCollector (#1151)
Browse files Browse the repository at this point in the history
* [PostRector] Improve UseNodesToAddCollector

* move $fullyQualifiedObjectType->getShortNameLowered() to outside loop on ClassLikeNameClassNameImportSkipVoter

* [ci-review] Rector Rectify

* early compare to [] before check ->getShortNameLowered()

Co-authored-by: GitHub Action <action@github.com>
  • Loading branch information
samsonasik and actions-user committed Nov 5, 2021
1 parent 1e94a70 commit 9b68637
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/PostRector/Collector/UseNodesToAddCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public function isShortImported(File $file, FullyQualifiedObjectType $fullyQuali

$fileFunctionUseImportTypes = $this->functionUseImportTypesInFilePath[$filePath] ?? [];
foreach ($fileFunctionUseImportTypes as $fileFunctionUseImportType) {
if ($fileFunctionUseImportType->getShortName() === $fullyQualifiedObjectType->getShortName()) {
if ($fileFunctionUseImportType->getShortName() === $shortName) {
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,13 @@ public function __construct(
public function shouldSkip(File $file, FullyQualifiedObjectType $fullyQualifiedObjectType, Node $node): bool
{
$classLikeNames = $this->shortNameResolver->resolveShortClassLikeNamesForNode($node);
if ($classLikeNames === []) {
return false;
}

$shortNameLowered = $fullyQualifiedObjectType->getShortNameLowered();
foreach ($classLikeNames as $classLikeName) {
if (strtolower($classLikeName) === $fullyQualifiedObjectType->getShortNameLowered()) {
if (strtolower($classLikeName) === $shortNameLowered) {
return true;
}
}
Expand Down

0 comments on commit 9b68637

Please sign in to comment.