mirror of
https://github.com/rectorphp/rector.git
synced 2025-02-24 11:44:14 +01:00
Merge pull request #2979 from rectorphp/fix-spacing
fix spacing for array shape item
This commit is contained in:
commit
3b74b47a97
@ -4,11 +4,45 @@ declare(strict_types=1);
|
||||
|
||||
namespace Rector\AttributeAwarePhpDoc\Ast\Type;
|
||||
|
||||
use Nette\Utils\Strings;
|
||||
use PHPStan\PhpDocParser\Ast\ConstExpr\ConstExprIntegerNode;
|
||||
use PHPStan\PhpDocParser\Ast\Type\ArrayShapeItemNode;
|
||||
use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode;
|
||||
use PHPStan\PhpDocParser\Ast\Type\TypeNode;
|
||||
use Rector\BetterPhpDocParser\Attributes\Attribute\AttributeTrait;
|
||||
use Rector\BetterPhpDocParser\Contract\PhpDocNode\AttributeAwareNodeInterface;
|
||||
|
||||
final class AttributeAwareArrayShapeItemNode extends ArrayShapeItemNode implements AttributeAwareNodeInterface
|
||||
{
|
||||
use AttributeTrait;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
private $hasSpaceAfterDoubleColon = false;
|
||||
|
||||
/**
|
||||
* @param ConstExprIntegerNode|IdentifierTypeNode|null $keyName
|
||||
*/
|
||||
public function __construct($keyName, bool $optional, TypeNode $typeNode, string $docComment = '')
|
||||
{
|
||||
parent::__construct($keyName, $optional, $typeNode);
|
||||
|
||||
$this->hasSpaceAfterDoubleColon = (bool) Strings::match($docComment, '#\:\s+#');
|
||||
}
|
||||
|
||||
public function __toString(): string
|
||||
{
|
||||
if ($this->keyName === null) {
|
||||
return (string) $this->valueType;
|
||||
}
|
||||
|
||||
return sprintf(
|
||||
'%s%s:%s%s',
|
||||
(string) $this->keyName,
|
||||
$this->optional ? '?' : '',
|
||||
$this->hasSpaceAfterDoubleColon ? ' ' : '',
|
||||
(string) $this->valueType
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -7,11 +7,18 @@ namespace Rector\AttributeAwarePhpDoc\AttributeAwareNodeFactory\Type;
|
||||
use PHPStan\PhpDocParser\Ast\Node;
|
||||
use PHPStan\PhpDocParser\Ast\Type\ArrayShapeItemNode;
|
||||
use Rector\AttributeAwarePhpDoc\Ast\Type\AttributeAwareArrayShapeItemNode;
|
||||
use Rector\AttributeAwarePhpDoc\Contract\AttributeNodeAwareFactory\AttributeAwareNodeFactoryAwareInterface;
|
||||
use Rector\AttributeAwarePhpDoc\Contract\AttributeNodeAwareFactory\AttributeNodeAwareFactoryInterface;
|
||||
use Rector\BetterPhpDocParser\Attributes\Ast\AttributeAwareNodeFactory;
|
||||
use Rector\BetterPhpDocParser\Contract\PhpDocNode\AttributeAwareNodeInterface;
|
||||
|
||||
final class AttributeAwareArrayShapeItemNodeFactory implements AttributeNodeAwareFactoryInterface
|
||||
final class AttributeAwareArrayShapeItemNodeFactory implements AttributeNodeAwareFactoryInterface, AttributeAwareNodeFactoryAwareInterface
|
||||
{
|
||||
/**
|
||||
* @var AttributeAwareNodeFactory
|
||||
*/
|
||||
private $attributeAwareNodeFactory;
|
||||
|
||||
public function getOriginalNodeClass(): string
|
||||
{
|
||||
return ArrayShapeItemNode::class;
|
||||
@ -27,6 +34,13 @@ final class AttributeAwareArrayShapeItemNodeFactory implements AttributeNodeAwar
|
||||
*/
|
||||
public function create(Node $node, string $docContent): AttributeAwareNodeInterface
|
||||
{
|
||||
return new AttributeAwareArrayShapeItemNode($node->keyName, $node->optional, $node->valueType);
|
||||
$node->valueType = $this->attributeAwareNodeFactory->createFromNode($node->valueType, $docContent);
|
||||
|
||||
return new AttributeAwareArrayShapeItemNode($node->keyName, $node->optional, $node->valueType, $docContent);
|
||||
}
|
||||
|
||||
public function setAttributeAwareNodeFactory(AttributeAwareNodeFactory $attributeAwareNodeFactory): void
|
||||
{
|
||||
$this->attributeAwareNodeFactory = $attributeAwareNodeFactory;
|
||||
}
|
||||
}
|
||||
|
@ -36,8 +36,7 @@ final class AttributeAwareArrayShapeNodeFactory implements AttributeNodeAwareFac
|
||||
{
|
||||
$items = [];
|
||||
foreach ($node->items as $item) {
|
||||
$item->valueType = $this->attributeAwareNodeFactory->createFromNode($item->valueType, $docContent);
|
||||
$items[] = $item;
|
||||
$items[] = $this->attributeAwareNodeFactory->createFromNode($item, $docContent);
|
||||
}
|
||||
|
||||
return new AttributeAwareArrayShapeNode($items);
|
||||
|
@ -0,0 +1,5 @@
|
||||
/**
|
||||
* normal view template will be rendered.
|
||||
*
|
||||
* @var array{serialize:string|bool|null}
|
||||
*/
|
Loading…
x
Reference in New Issue
Block a user