diff --git a/rules/TypeDeclaration/PHPStan/ObjectTypeSpecifier.php b/rules/TypeDeclaration/PHPStan/ObjectTypeSpecifier.php index 012345a8744..10e30330fe7 100644 --- a/rules/TypeDeclaration/PHPStan/ObjectTypeSpecifier.php +++ b/rules/TypeDeclaration/PHPStan/ObjectTypeSpecifier.php @@ -51,14 +51,16 @@ public function narrowToFullyQualifiedOrAliasedObjectType( $uses = $this->useImportsResolver->resolve(); - $aliasedObjectType = $this->matchAliasedObjectType($objectType, $uses); - if ($aliasedObjectType instanceof AliasedObjectType) { - return $aliasedObjectType; - } + if (! $withPreslash) { + $aliasedObjectType = $this->matchAliasedObjectType($objectType, $uses); + if ($aliasedObjectType instanceof AliasedObjectType) { + return $aliasedObjectType; + } - $shortenedObjectType = $this->matchShortenedObjectType($objectType, $uses); - if ($shortenedObjectType !== null) { - return $shortenedObjectType; + $shortenedObjectType = $this->matchShortenedObjectType($objectType, $uses); + if ($shortenedObjectType !== null) { + return $shortenedObjectType; + } } if ($this->reflectionProvider->hasClass($className)) { diff --git a/stubs/Carbon/CarbonInterface.php b/stubs/Carbon/CarbonInterface.php new file mode 100644 index 00000000000..e269ec39d80 --- /dev/null +++ b/stubs/Carbon/CarbonInterface.php @@ -0,0 +1,12 @@ + +----- + \ No newline at end of file diff --git a/tests/Issues/NamespacedUseAutoImport/Fixture/not_in_use_fqcn_docblock.php.inc b/tests/Issues/NamespacedUseAutoImport/Fixture/not_in_use_fqcn_docblock.php.inc new file mode 100644 index 00000000000..fe157429394 --- /dev/null +++ b/tests/Issues/NamespacedUseAutoImport/Fixture/not_in_use_fqcn_docblock.php.inc @@ -0,0 +1,43 @@ + +----- + diff --git a/tests/Issues/NamespacedUseAutoImport/Fixture/not_in_use_fqcn_docblock_2.inc b/tests/Issues/NamespacedUseAutoImport/Fixture/not_in_use_fqcn_docblock_2.inc new file mode 100644 index 00000000000..07b93a9e88d --- /dev/null +++ b/tests/Issues/NamespacedUseAutoImport/Fixture/not_in_use_fqcn_docblock_2.inc @@ -0,0 +1,42 @@ + +----- +