Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Micro optimizations: cheap checks first #4510

Merged
merged 2 commits into from
Jul 14, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,14 @@ public function __construct(

public function shouldSkipClassMethod(ClassMethod $classMethod, Scope $scope): bool
{
// 1. skip magic methods
staabm marked this conversation as resolved.
Show resolved Hide resolved
if ($classMethod->returnType instanceof Node) {
return true;
}

if ($classMethod->isMagic()) {
return true;
}

// 2. skip chaotic contract class methods
if ($this->shouldSkipChaoticClassMethods($classMethod)) {
return true;
}
Expand All @@ -80,10 +82,6 @@ public function shouldSkipClassMethod(ClassMethod $classMethod, Scope $scope): b
return false;
}

if ($classMethod->returnType instanceof Node) {
staabm marked this conversation as resolved.
Show resolved Hide resolved
return true;
}

if ($this->shouldSkipHasChildHasReturnType($childrenClassReflections, $classMethod)) {
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,17 +83,17 @@ public function refactorWithScope(Node $node, Scope $scope): ?Node
{
$returnType = $node->getReturnType();

if ($returnType === null) {
return null;
}

if ($node instanceof ClassMethod && $this->classMethodReturnTypeOverrideGuard->shouldSkipClassMethod(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need to invoke the type-overridde-guard, if we already have a return type

$node,
$scope
)) {
return null;
}

if ($returnType === null) {
return null;
}

if (! $this->phpDocNestedAnnotationGuard->isPhpDocCommentCorrectlyParsed($node)) {
return null;
}
Expand Down