mirror of
https://github.com/rectorphp/rector.git
synced 2025-02-23 11:14:38 +01:00
improve original format in CallableTypeNode
This commit is contained in:
parent
f8446a60b0
commit
daba8df475
@ -5,6 +5,7 @@ declare(strict_types=1);
|
||||
namespace Rector\AttributeAwarePhpDoc\Ast\Type;
|
||||
|
||||
use PHPStan\PhpDocParser\Ast\Type\CallableTypeNode;
|
||||
use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode;
|
||||
use Rector\BetterPhpDocParser\Attributes\Attribute\AttributeTrait;
|
||||
use Rector\BetterPhpDocParser\Contract\PhpDocNode\AttributeAwareNodeInterface;
|
||||
|
||||
@ -14,6 +15,28 @@ final class AttributeAwareCallableTypeNode extends CallableTypeNode implements A
|
||||
|
||||
public function __toString(): string
|
||||
{
|
||||
// keep original (Psalm?) format, see https://github.com/rectorphp/rector/issues/2841
|
||||
if ($this->isExplicitCallable()) {
|
||||
return $this->createExplicitCallable();
|
||||
}
|
||||
|
||||
return 'callable';
|
||||
}
|
||||
|
||||
private function isExplicitCallable(): bool
|
||||
{
|
||||
if (! $this->returnType instanceof IdentifierTypeNode) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->returnType->name !== 'mixed';
|
||||
}
|
||||
|
||||
private function createExplicitCallable(): string
|
||||
{
|
||||
/** @var IdentifierTypeNode $returnType */
|
||||
$returnType = $this->returnType;
|
||||
|
||||
return $this->identifier->name . '():' . $returnType->name;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user