add brackets in case of array of callables in php doc

This commit is contained in:
TomasVotruba 2020-06-15 16:19:01 +02:00
parent 508954fc74
commit 9135bff8eb

View File

@ -5,10 +5,22 @@ declare(strict_types=1);
namespace Rector\AttributeAwarePhpDoc\Ast\Type;
use PHPStan\PhpDocParser\Ast\Type\ArrayTypeNode;
use PHPStan\PhpDocParser\Ast\Type\CallableTypeNode;
use Rector\BetterPhpDocParser\Attributes\Attribute\AttributeTrait;
use Rector\BetterPhpDocParser\Contract\PhpDocNode\AttributeAwareNodeInterface;
final class AttributeAwareArrayTypeNode extends ArrayTypeNode implements AttributeAwareNodeInterface
{
use AttributeTrait;
public function __toString(): string
{
$typeAsString = (string) $this->type;
if ($this->type instanceof CallableTypeNode) {
return sprintf('(%s)[]', $typeAsString);
}
return $typeAsString . '[]';
}
}