diff --git a/packages/PostRector/Collector/UseNodesToAddCollector.php b/packages/PostRector/Collector/UseNodesToAddCollector.php index 2f356492a54..55cd579ebbb 100644 --- a/packages/PostRector/Collector/UseNodesToAddCollector.php +++ b/packages/PostRector/Collector/UseNodesToAddCollector.php @@ -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; } } diff --git a/rules/CodingStyle/ClassNameImport/ClassNameImportSkipVoter/ClassLikeNameClassNameImportSkipVoter.php b/rules/CodingStyle/ClassNameImport/ClassNameImportSkipVoter/ClassLikeNameClassNameImportSkipVoter.php index ff215d96144..ab35fe544d1 100644 --- a/rules/CodingStyle/ClassNameImport/ClassNameImportSkipVoter/ClassLikeNameClassNameImportSkipVoter.php +++ b/rules/CodingStyle/ClassNameImport/ClassNameImportSkipVoter/ClassLikeNameClassNameImportSkipVoter.php @@ -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; } }