mirror of
https://github.com/rectorphp/rector.git
synced 2024-06-07 03:40:50 +00:00
[TypeDeclaration] Skip return type defined Closure on ReturnTypeDeclarationRector (#2179)
* [TypeDeclaration] Skip return type defined Closure on ReturnTypeDeclarationRector
* Fixed 🎉
* [ci-review] Rector Rectify
* [ci-review] Rector Rectify
* Fix
* final touch: clean up
* [ci-review] Rector Rectify
* [ci-review] Rector Rectify
Co-authored-by: GitHub Action <action@github.com>
This commit is contained in:
parent
ae45be1cf3
commit
4fea4e23b9
|
@ -5,7 +5,7 @@ declare(strict_types=1);
|
|||
namespace Rector\PHPStanStaticTypeMapper\TypeMapper;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Name;
|
||||
use PhpParser\Node\Name\FullyQualified;
|
||||
use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode;
|
||||
use PHPStan\PhpDocParser\Ast\Type\TypeNode;
|
||||
use PHPStan\Type\ClosureType;
|
||||
|
@ -55,7 +55,7 @@ final class ClosureTypeMapper implements TypeMapperInterface
|
|||
return null;
|
||||
}
|
||||
|
||||
return new Name('callable');
|
||||
return new FullyQualified('Closure');
|
||||
}
|
||||
|
||||
#[Required]
|
||||
|
|
|
@ -0,0 +1,53 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\Tests\TypeDeclaration\Rector\FunctionLike\ReturnTypeDeclarationRector\Fixture;
|
||||
|
||||
class ClosureNestedType
|
||||
{
|
||||
private function collectionCallback(): callable
|
||||
{
|
||||
return function (int $offset, int $itemCountPerPage): iterable {
|
||||
$stmt = $this->connection->executeQuery('SELECT * FROM *');
|
||||
|
||||
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
|
||||
yield EventsEntity::forCollection();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private function again(): callable
|
||||
{
|
||||
return function (int $offset, int $itemCountPerPage): iterable {
|
||||
return 25;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\Tests\TypeDeclaration\Rector\FunctionLike\ReturnTypeDeclarationRector\Fixture;
|
||||
|
||||
class ClosureNestedType
|
||||
{
|
||||
private function collectionCallback(): \Closure
|
||||
{
|
||||
return function (int $offset, int $itemCountPerPage): iterable {
|
||||
$stmt = $this->connection->executeQuery('SELECT * FROM *');
|
||||
|
||||
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
|
||||
yield EventsEntity::forCollection();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private function again(): \Closure
|
||||
{
|
||||
return function (int $offset, int $itemCountPerPage): iterable {
|
||||
return 25;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
|
@ -67,7 +67,7 @@ class KnownStatic
|
|||
return [];
|
||||
}
|
||||
|
||||
public function getCallable(): callable
|
||||
public function getCallable(): \Closure
|
||||
{
|
||||
return function () {
|
||||
};
|
||||
|
|
|
@ -1,24 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\Tests\TypeDeclaration\Rector\FunctionLike\ReturnTypeDeclarationRector\Fixture;
|
||||
|
||||
class SkipAnonymousFunctionNestedType
|
||||
{
|
||||
private function collectionCallback(): callable
|
||||
{
|
||||
return function (int $offset, int $itemCountPerPage): iterable {
|
||||
$stmt = $this->connection->executeQuery('SELECT * FROM *');
|
||||
|
||||
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
|
||||
yield EventsEntity::forCollection();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private function again(): callable
|
||||
{
|
||||
return function (int $offset, int $itemCountPerPage): iterable {
|
||||
return 25;
|
||||
};
|
||||
}
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\Tests\TypeDeclaration\Rector\FunctionLike\ReturnTypeDeclarationRector\Fixture;
|
||||
|
||||
use Closure;
|
||||
|
||||
final class skipReturnClosureToCallable
|
||||
{
|
||||
public function run(): Closure
|
||||
{
|
||||
return fn ($query) => $query->where('id', 1);
|
||||
}
|
||||
}
|
|
@ -46,7 +46,7 @@ final class ReturnTypeDeclarationRector extends AbstractRector implements MinPhp
|
|||
private readonly ClassMethodReturnTypeOverrideGuard $classMethodReturnTypeOverrideGuard,
|
||||
private readonly VendorLockResolver $vendorLockResolver,
|
||||
private readonly PhpParserTypeAnalyzer $phpParserTypeAnalyzer,
|
||||
private readonly ObjectTypeComparator $objectTypeComparator,
|
||||
private readonly ObjectTypeComparator $objectTypeComparator
|
||||
) {
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user