Skip to content

Commit

Permalink
register rule
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed Mar 6, 2024
1 parent e6cc1b7 commit 9f7e867
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
namespace Rector\TypeDeclaration\Rector\Class_;

use PhpParser\Node;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Identifier;
use PhpParser\Node\Name;
use PhpParser\Node\NullableType;
use PhpParser\Node\Stmt\Class_;
Expand Down Expand Up @@ -152,21 +154,19 @@ private function resolveEntityClassnameFromPhpDoc(Class_ $class): ?string
return null;
}

$entityClassName = $entityGenericType->name;

return $entityClassName;
return $entityGenericType->name;
}

private function containsMethodCallNamed(ClassMethod $classMethod, string $desiredMethodName): bool
{
return (bool) $this->nodeFinder->findFirst((array) $classMethod->stmts, function (\PhpParser\Node $node) use (
return (bool) $this->nodeFinder->findFirst((array) $classMethod->stmts, static function (Node $node) use (
$desiredMethodName
): bool {
if (! $node instanceof Node\Expr\MethodCall) {
if (! $node instanceof MethodCall) {
return false;
}

if (! $node->name instanceof Node\Identifier) {
if (! $node->name instanceof Identifier) {
return false;
}

Expand All @@ -185,11 +185,7 @@ private function shouldSkipClassMethod(ClassMethod $classMethod): bool
return true;
}

if ($classMethod->returnType instanceof \PhpParser\Node) {
return true;
}

return false;
return $classMethod->returnType instanceof Node;
}

private function createNullableType(string $entityClassName): NullableType
Expand Down
2 changes: 2 additions & 0 deletions src/Config/Level/TypeDeclarationLevel.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Rector\Contract\Rector\RectorInterface;
use Rector\TypeDeclaration\Rector\ArrowFunction\AddArrowFunctionReturnTypeRector;
use Rector\TypeDeclaration\Rector\Class_\AddTestsVoidReturnTypeWhereNoReturnRector;
use Rector\TypeDeclaration\Rector\Class_\ChildDoctrineRepositoryClassTypeRector;
use Rector\TypeDeclaration\Rector\Class_\MergeDateTimePropertyTypeDeclarationRector;
use Rector\TypeDeclaration\Rector\Class_\PropertyTypeFromStrictSetterGetterRector;
use Rector\TypeDeclaration\Rector\Class_\ReturnTypeFromStrictTernaryRector;
Expand Down Expand Up @@ -85,6 +86,7 @@ final class TypeDeclarationLevel
TypedPropertyFromStrictSetUpRector::class,
ReturnTypeFromStrictNativeCallRector::class,
ReturnTypeFromStrictTypedCallRector::class,
ChildDoctrineRepositoryClassTypeRector::class,

// param
AddMethodCallBasedStrictParamTypeRector::class,
Expand Down

0 comments on commit 9f7e867

Please sign in to comment.