diff --git a/rules/TypeDeclaration/PHPStan/ObjectTypeSpecifier.php b/rules/TypeDeclaration/PHPStan/ObjectTypeSpecifier.php index 608707ce97..aa643275ad 100644 --- a/rules/TypeDeclaration/PHPStan/ObjectTypeSpecifier.php +++ b/rules/TypeDeclaration/PHPStan/ObjectTypeSpecifier.php @@ -44,6 +44,11 @@ public function narrowToFullyQualifiedOrAliasedObjectType( Scope|null $scope, bool $withPreslash = false ): TypeWithClassName | NonExistingObjectType | UnionType | MixedType | TemplateType { + $className = ltrim($objectType->getClassName(), '\\'); + if (str_starts_with($objectType->getClassName(), '\\')) { + return new FullyQualifiedObjectType($className); + } + $uses = $this->useImportsResolver->resolve(); $aliasedObjectType = $this->matchAliasedObjectType($objectType, $uses); @@ -56,11 +61,6 @@ public function narrowToFullyQualifiedOrAliasedObjectType( return $shortenedObjectType; } - $className = ltrim($objectType->getClassName(), '\\'); - if (str_starts_with($objectType->getClassName(), '\\')) { - return new FullyQualifiedObjectType($className); - } - if ($this->reflectionProvider->hasClass($className)) { return new FullyQualifiedObjectType($className); }