Skip to content

Commit

Permalink
[Performance] Early return FullyQualifiedObjectType on FQCN on Object…
Browse files Browse the repository at this point in the history
…TypeSpecifier
  • Loading branch information
samsonasik committed Jan 6, 2025
1 parent 4b18c82 commit a328d37
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions rules/TypeDeclaration/PHPStan/ObjectTypeSpecifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}
Expand Down

0 comments on commit a328d37

Please sign in to comment.