[PhpDocParser] Make use of native attributes (#5841)

Co-authored-by: kaizen-ci <info@kaizen-ci.org>
This commit is contained in:
Tomas Votruba 2021-03-19 15:33:58 +01:00 committed by GitHub
parent abed1ff280
commit 025e6ed571
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
141 changed files with 579 additions and 1938 deletions

View File

@ -38,8 +38,8 @@
"nette/robot-loader": "^3.4",
"nette/utils": "^3.2",
"nikic/php-parser": "^4.10.4",
"phpstan/phpdoc-parser": "^0.5",
"phpstan/phpstan": "^0.12.82",
"phpstan/phpdoc-parser": "^0.5.1",
"phpstan/phpstan-phpunit": "^0.12.18",
"rector/rector-symfony": "dev-main",
"rector/rector-nette": "dev-main",
@ -52,20 +52,20 @@
"symfony/http-kernel": "^4.4.8|^5.1",
"symfony/process": "^4.4.8|^5.1",
"symfony/uid": "^4.4.8|^5.1",
"symplify/astral": "^9.2",
"symplify/autowire-array-parameter": "^9.2",
"symplify/console-color-diff": "^9.2",
"symplify/package-builder": "^9.2",
"symplify/rule-doc-generator-contracts": "^9.2",
"symplify/set-config-resolver": "^9.2",
"symplify/simple-php-doc-parser": "^9.2",
"symplify/skipper": "^9.2",
"symplify/smart-file-system": "^9.2",
"symplify/symfony-php-config": "^9.2",
"symplify/astral": "^9.2.12",
"symplify/autowire-array-parameter": "^9.2.12",
"symplify/console-color-diff": "^9.2.12",
"symplify/package-builder": "^9.2.12",
"symplify/rule-doc-generator-contracts": "^9.2.12",
"symplify/set-config-resolver": "^9.2.12",
"symplify/simple-php-doc-parser": "^9.2.12",
"symplify/skipper": "^9.2.12",
"symplify/smart-file-system": "^9.2.12",
"symplify/symfony-php-config": "^9.2.12",
"webmozart/assert": "^1.10"
},
"require-dev": {
"symplify/rule-doc-generator": "^9.2",
"symplify/rule-doc-generator": "^9.2.12",
"friendsofphp/php-cs-fixer": "^2.18.3",
"nette/application": "^3.0.7",
"nette/di": "^3.0",
@ -73,11 +73,11 @@
"phpstan/phpstan-nette": "^0.12.16",
"phpunit/phpunit": "^9.5",
"rector/rector-generator": "^0.1.1",
"symplify/coding-standard": "^9.2",
"symplify/easy-ci": "^9.2",
"symplify/easy-coding-standard": "^9.2",
"symplify/easy-testing": "^9.2",
"symplify/phpstan-extensions": "^9.2",
"symplify/coding-standard": "^9.2.12",
"symplify/easy-ci": "^9.2.12",
"symplify/easy-coding-standard": "^9.2.12",
"symplify/easy-testing": "^9.2.12",
"symplify/phpstan-extensions": "^9.2.12",
"symplify/phpstan-rules": "^9.2",
"tracy/tracy": "^2.8"
},

View File

@ -11,9 +11,6 @@ use PHPStan\PhpDocParser\Ast\PhpDoc\PropertyTagValueNode;
use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode;
use PHPStan\PhpDocParser\Ast\Type\NullableTypeNode;
use Rector\AttributeAwarePhpDoc\Ast\PhpDoc\AttributeAwarePhpDocNode;
use Rector\AttributeAwarePhpDoc\Ast\PhpDoc\AttributeAwarePropertyTagValueNode;
use Rector\AttributeAwarePhpDoc\Ast\Type\AttributeAwareIdentifierTypeNode;
use Rector\AttributeAwarePhpDoc\Ast\Type\AttributeAwareNullableTypeNode;
use Rector\BetterPhpDocParser\Attributes\Ast\AttributeAwareNodeFactory;
use Rector\Core\HttpKernel\RectorKernel;
use Symplify\PackageBuilder\Testing\AbstractKernelTestCase;
@ -57,28 +54,17 @@ final class AttributeAwareNodeFactoryTest extends AbstractKernelTestCase
/** @var PhpDocTagNode $childNode */
$propertyTagValueNode = $childNode->value;
$this->assertInstanceOf(PropertyTagValueNode::class, $propertyTagValueNode);
$this->assertInstanceOf(AttributeAwarePropertyTagValueNode::class, $propertyTagValueNode);
// test nullable
/** @var PropertyTagValueNode $propertyTagValueNode */
$nullableTypeNode = $propertyTagValueNode->type;
$this->assertInstanceOf(NullableTypeNode::class, $nullableTypeNode);
$this->assertInstanceOf(AttributeAwareNullableTypeNode::class, $nullableTypeNode);
// test type inside nullable
/** @var NullableTypeNode $nullableTypeNode */
$identifierTypeNode = $nullableTypeNode->type;
$this->assertInstanceOf(IdentifierTypeNode::class, $identifierTypeNode);
$this->assertInstanceOf(AttributeAwareIdentifierTypeNode::class, $identifierTypeNode);
}
public function testAlreadyAttributeAware(): void
{
$attributeAwarePhpDocNode = new AttributeAwarePhpDocNode([]);
$returnedNode = $this->attributeAwareNodeFactory->createFromNode($attributeAwarePhpDocNode, '');
$this->assertSame($returnedNode, $attributeAwarePhpDocNode);
}
/**

View File

@ -1,16 +0,0 @@
<?php
declare(strict_types=1);
namespace Rector\Tests\BetterPhpDocParser\PhpDocParser\TagValueNodeReprint\Fixture\DoctrineTable;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Table(name="amenity_building", uniqueConstraints={@ORM\UniqueConstraint(name="building_id_amenity_id",
* columns={"building_id", "amenity_id"})}
* )
*/
final class TableWithIndexes
{
}

View File

@ -1,14 +0,0 @@
<?php
declare(strict_types=1);
namespace Rector\AttributeAwarePhpDoc\Ast\PhpDoc;
use PHPStan\PhpDocParser\Ast\PhpDoc\DeprecatedTagValueNode;
use Rector\BetterPhpDocParser\Attributes\Attribute\AttributeTrait;
use Rector\BetterPhpDocParser\Contract\PhpDocNode\AttributeAwareNodeInterface;
final class AttributeAwareDeprecatedTagValueNode extends DeprecatedTagValueNode implements AttributeAwareNodeInterface
{
use AttributeTrait;
}

View File

@ -1,14 +0,0 @@
<?php
declare(strict_types=1);
namespace Rector\AttributeAwarePhpDoc\Ast\PhpDoc;
use PHPStan\PhpDocParser\Ast\PhpDoc\ExtendsTagValueNode;
use Rector\BetterPhpDocParser\Attributes\Attribute\AttributeTrait;
use Rector\BetterPhpDocParser\Contract\PhpDocNode\AttributeAwareNodeInterface;
final class AttributeAwareExtendsTagValueNode extends ExtendsTagValueNode implements AttributeAwareNodeInterface
{
use AttributeTrait;
}

View File

@ -1,14 +0,0 @@
<?php
declare(strict_types=1);
namespace Rector\AttributeAwarePhpDoc\Ast\PhpDoc;
use PHPStan\PhpDocParser\Ast\PhpDoc\GenericTagValueNode;
use Rector\BetterPhpDocParser\Attributes\Attribute\AttributeTrait;
use Rector\BetterPhpDocParser\Contract\PhpDocNode\AttributeAwareNodeInterface;
final class AttributeAwareGenericTagValueNode extends GenericTagValueNode implements AttributeAwareNodeInterface
{
use AttributeTrait;
}

View File

@ -1,14 +0,0 @@
<?php
declare(strict_types=1);
namespace Rector\AttributeAwarePhpDoc\Ast\PhpDoc;
use PHPStan\PhpDocParser\Ast\PhpDoc\ImplementsTagValueNode;
use Rector\BetterPhpDocParser\Attributes\Attribute\AttributeTrait;
use Rector\BetterPhpDocParser\Contract\PhpDocNode\AttributeAwareNodeInterface;
final class AttributeAwareImplementsTagValueNode extends ImplementsTagValueNode implements AttributeAwareNodeInterface
{
use AttributeTrait;
}

View File

@ -1,14 +0,0 @@
<?php
declare(strict_types=1);
namespace Rector\AttributeAwarePhpDoc\Ast\PhpDoc;
use PHPStan\PhpDocParser\Ast\PhpDoc\InvalidTagValueNode;
use Rector\BetterPhpDocParser\Attributes\Attribute\AttributeTrait;
use Rector\BetterPhpDocParser\Contract\PhpDocNode\AttributeAwareNodeInterface;
final class AttributeAwareInvalidTagValueNode extends InvalidTagValueNode implements AttributeAwareNodeInterface
{
use AttributeTrait;
}

View File

@ -1,14 +0,0 @@
<?php
declare(strict_types=1);
namespace Rector\AttributeAwarePhpDoc\Ast\PhpDoc;
use PHPStan\PhpDocParser\Ast\PhpDoc\MethodTagValueNode;
use Rector\BetterPhpDocParser\Attributes\Attribute\AttributeTrait;
use Rector\BetterPhpDocParser\Contract\PhpDocNode\AttributeAwareNodeInterface;
final class AttributeAwareMethodTagValueNode extends MethodTagValueNode implements AttributeAwareNodeInterface
{
use AttributeTrait;
}

View File

@ -1,14 +0,0 @@
<?php
declare(strict_types=1);
namespace Rector\AttributeAwarePhpDoc\Ast\PhpDoc;
use PHPStan\PhpDocParser\Ast\PhpDoc\MethodTagValueParameterNode;
use Rector\BetterPhpDocParser\Attributes\Attribute\AttributeTrait;
use Rector\BetterPhpDocParser\Contract\PhpDocNode\AttributeAwareNodeInterface;
final class AttributeAwareMethodTagValueParameterNode extends MethodTagValueParameterNode implements AttributeAwareNodeInterface
{
use AttributeTrait;
}

View File

@ -1,14 +0,0 @@
<?php
declare(strict_types=1);
namespace Rector\AttributeAwarePhpDoc\Ast\PhpDoc;
use PHPStan\PhpDocParser\Ast\PhpDoc\MixinTagValueNode;
use Rector\BetterPhpDocParser\Attributes\Attribute\AttributeTrait;
use Rector\BetterPhpDocParser\Contract\PhpDocNode\AttributeAwareNodeInterface;
final class AttributeAwareMixinTagValueNode extends MixinTagValueNode implements AttributeAwareNodeInterface
{
use AttributeTrait;
}

View File

@ -5,14 +5,9 @@ declare(strict_types=1);
namespace Rector\AttributeAwarePhpDoc\Ast\PhpDoc;
use PHPStan\PhpDocParser\Ast\PhpDoc\ParamTagValueNode;
use Rector\BetterPhpDocParser\Attributes\Attribute\AttributeTrait;
use Rector\BetterPhpDocParser\Contract\PhpDocNode\AttributeAwareNodeInterface;
use Rector\BetterPhpDocParser\Contract\PhpDocNode\TypeAwareTagValueNodeInterface;
final class AttributeAwareParamTagValueNode extends ParamTagValueNode implements AttributeAwareNodeInterface, TypeAwareTagValueNodeInterface
final class AttributeAwareParamTagValueNode extends ParamTagValueNode
{
use AttributeTrait;
public function __toString(): string
{
$variadic = $this->isVariadic ? '...' : '';

View File

@ -4,17 +4,16 @@ declare(strict_types=1);
namespace Rector\AttributeAwarePhpDoc\Ast\PhpDoc;
use PHPStan\PhpDocParser\Ast\NodeAttributes;
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocChildNode;
use Rector\BetterPhpDocParser\Attributes\Attribute\AttributeTrait;
use Rector\BetterPhpDocParser\Contract\PhpDocNode\AttributeAwareNodeInterface;
use Symplify\SimplePhpDocParser\ValueObject\Ast\PhpDoc\SimplePhpDocNode;
final class AttributeAwarePhpDocNode extends SimplePhpDocNode implements AttributeAwareNodeInterface
final class AttributeAwarePhpDocNode extends SimplePhpDocNode
{
use AttributeTrait;
use NodeAttributes;
/**
* @var PhpDocChildNode[]|AttributeAwareNodeInterface[]
* @var array<PhpDocChildNode>
*/
public $children = [];

View File

@ -1,14 +0,0 @@
<?php
declare(strict_types=1);
namespace Rector\AttributeAwarePhpDoc\Ast\PhpDoc;
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode;
use Rector\BetterPhpDocParser\Attributes\Attribute\AttributeTrait;
use Rector\BetterPhpDocParser\Contract\PhpDocNode\AttributeAwareNodeInterface;
final class AttributeAwarePhpDocTagNode extends PhpDocTagNode implements AttributeAwareNodeInterface
{
use AttributeTrait;
}

View File

@ -1,14 +0,0 @@
<?php
declare(strict_types=1);
namespace Rector\AttributeAwarePhpDoc\Ast\PhpDoc;
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTextNode;
use Rector\BetterPhpDocParser\Attributes\Attribute\AttributeTrait;
use Rector\BetterPhpDocParser\Contract\PhpDocNode\AttributeAwareNodeInterface;
final class AttributeAwarePhpDocTextNode extends PhpDocTextNode implements AttributeAwareNodeInterface
{
use AttributeTrait;
}

View File

@ -1,15 +0,0 @@
<?php
declare(strict_types=1);
namespace Rector\AttributeAwarePhpDoc\Ast\PhpDoc;
use PHPStan\PhpDocParser\Ast\PhpDoc\PropertyTagValueNode;
use Rector\BetterPhpDocParser\Attributes\Attribute\AttributeTrait;
use Rector\BetterPhpDocParser\Contract\PhpDocNode\AttributeAwareNodeInterface;
use Rector\BetterPhpDocParser\Contract\PhpDocNode\TypeAwareTagValueNodeInterface;
final class AttributeAwarePropertyTagValueNode extends PropertyTagValueNode implements AttributeAwareNodeInterface, TypeAwareTagValueNodeInterface
{
use AttributeTrait;
}

View File

@ -1,15 +0,0 @@
<?php
declare(strict_types=1);
namespace Rector\AttributeAwarePhpDoc\Ast\PhpDoc;
use PHPStan\PhpDocParser\Ast\PhpDoc\ReturnTagValueNode;
use Rector\BetterPhpDocParser\Attributes\Attribute\AttributeTrait;
use Rector\BetterPhpDocParser\Contract\PhpDocNode\AttributeAwareNodeInterface;
use Rector\BetterPhpDocParser\Contract\PhpDocNode\TypeAwareTagValueNodeInterface;
final class AttributeAwareReturnTagValueNode extends ReturnTagValueNode implements AttributeAwareNodeInterface, TypeAwareTagValueNodeInterface
{
use AttributeTrait;
}

View File

@ -7,13 +7,9 @@ namespace Rector\AttributeAwarePhpDoc\Ast\PhpDoc;
use Nette\Utils\Strings;
use PHPStan\PhpDocParser\Ast\PhpDoc\TemplateTagValueNode;
use PHPStan\PhpDocParser\Ast\Type\TypeNode;
use Rector\BetterPhpDocParser\Attributes\Attribute\AttributeTrait;
use Rector\BetterPhpDocParser\Contract\PhpDocNode\AttributeAwareNodeInterface;
final class AttributeAwareTemplateTagValueNode extends TemplateTagValueNode implements AttributeAwareNodeInterface
final class AttributeAwareTemplateTagValueNode extends TemplateTagValueNode
{
use AttributeTrait;
/**
* @var string
* @see https://regex101.com/r/4WtsUS/1

View File

@ -1,15 +0,0 @@
<?php
declare(strict_types=1);
namespace Rector\AttributeAwarePhpDoc\Ast\PhpDoc;
use PHPStan\PhpDocParser\Ast\PhpDoc\ThrowsTagValueNode;
use Rector\BetterPhpDocParser\Attributes\Attribute\AttributeTrait;
use Rector\BetterPhpDocParser\Contract\PhpDocNode\AttributeAwareNodeInterface;
use Rector\BetterPhpDocParser\Contract\PhpDocNode\TypeAwareTagValueNodeInterface;
final class AttributeAwareThrowsTagValueNode extends ThrowsTagValueNode implements AttributeAwareNodeInterface, TypeAwareTagValueNodeInterface
{
use AttributeTrait;
}

View File

@ -1,14 +0,0 @@
<?php
declare(strict_types=1);
namespace Rector\AttributeAwarePhpDoc\Ast\PhpDoc;
use PHPStan\PhpDocParser\Ast\PhpDoc\UsesTagValueNode;
use Rector\BetterPhpDocParser\Attributes\Attribute\AttributeTrait;
use Rector\BetterPhpDocParser\Contract\PhpDocNode\AttributeAwareNodeInterface;
final class AttributeAwareUsesTagValueNode extends UsesTagValueNode implements AttributeAwareNodeInterface
{
use AttributeTrait;
}

View File

@ -1,15 +0,0 @@
<?php
declare(strict_types=1);
namespace Rector\AttributeAwarePhpDoc\Ast\PhpDoc;
use PHPStan\PhpDocParser\Ast\PhpDoc\VarTagValueNode;
use Rector\BetterPhpDocParser\Attributes\Attribute\AttributeTrait;
use Rector\BetterPhpDocParser\Contract\PhpDocNode\AttributeAwareNodeInterface;
use Rector\BetterPhpDocParser\Contract\PhpDocNode\TypeAwareTagValueNodeInterface;
final class AttributeAwareVarTagValueNode extends VarTagValueNode implements AttributeAwareNodeInterface, TypeAwareTagValueNodeInterface
{
use AttributeTrait;
}

View File

@ -4,13 +4,12 @@ declare(strict_types=1);
namespace Rector\AttributeAwarePhpDoc\Ast\PhpDoc;
use PHPStan\PhpDocParser\Ast\NodeAttributes;
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagValueNode;
use Rector\BetterPhpDocParser\Attributes\Attribute\AttributeTrait;
use Rector\BetterPhpDocParser\Contract\PhpDocNode\AttributeAwareNodeInterface;
final class DataProviderTagValueNode implements PhpDocTagValueNode, AttributeAwareNodeInterface
final class DataProviderTagValueNode implements PhpDocTagValueNode
{
use AttributeTrait;
use NodeAttributes;
/**
* @var string

View File

@ -4,19 +4,17 @@ declare(strict_types=1);
namespace Rector\AttributeAwarePhpDoc\Ast\PhpDoc;
use PHPStan\PhpDocParser\Ast\PhpDoc\GenericTagValueNode;
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode;
use Rector\BetterPhpDocParser\Attributes\Attribute\AttributeTrait;
use Rector\BetterPhpDocParser\Contract\PhpDocNode\AttributeAwareNodeInterface;
use Rector\PhpAttribute\Contract\PhpAttributableTagNodeInterface;
/**
* Use by Symfony to autowire dependencies outside constructor,
* @see https://symfony.com/doc/current/service_container/autowiring.html#autowiring-other-methods-e-g-setters-and-public-typed-properties
*/
final class SymfonyRequiredTagNode extends PhpDocTagNode implements PhpAttributableTagNodeInterface, AttributeAwareNodeInterface
final class SymfonyRequiredTagNode extends PhpDocTagNode implements PhpAttributableTagNodeInterface
{
use AttributeTrait;
/**
* @var string
*/
@ -24,7 +22,7 @@ final class SymfonyRequiredTagNode extends PhpDocTagNode implements PhpAttributa
public function __construct()
{
parent::__construct(self::NAME, new AttributeAwareGenericTagValueNode(''));
parent::__construct(self::NAME, new GenericTagValueNode(''));
}
public function __toString(): string

View File

@ -10,13 +10,9 @@ use PHPStan\PhpDocParser\Ast\ConstExpr\ConstExprStringNode;
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
final class AttributeAwareArrayShapeItemNode extends ArrayShapeItemNode
{
use AttributeTrait;
/**
* @var bool
*/

View File

@ -1,14 +0,0 @@
<?php
declare(strict_types=1);
namespace Rector\AttributeAwarePhpDoc\Ast\Type;
use PHPStan\PhpDocParser\Ast\Type\ArrayShapeNode;
use Rector\BetterPhpDocParser\Attributes\Attribute\AttributeTrait;
use Rector\BetterPhpDocParser\Contract\PhpDocNode\AttributeAwareNodeInterface;
final class AttributeAwareArrayShapeNode extends ArrayShapeNode implements AttributeAwareNodeInterface
{
use AttributeTrait;
}

View File

@ -8,14 +8,11 @@ use PHPStan\PhpDocParser\Ast\Type\ArrayTypeNode;
use PHPStan\PhpDocParser\Ast\Type\CallableTypeNode;
use PHPStan\PhpDocParser\Ast\Type\TypeNode;
use PHPStan\PhpDocParser\Ast\Type\UnionTypeNode;
use Rector\BetterPhpDocParser\Attributes\Attribute\AttributeTrait;
use Rector\BetterPhpDocParser\Contract\PhpDocNode\AttributeAwareNodeInterface;
use Rector\PHPStanStaticTypeMapper\TypeMapper\ArrayTypeMapper;
final class AttributeAwareArrayTypeNode extends ArrayTypeNode implements AttributeAwareNodeInterface
final class AttributeAwareArrayTypeNode extends ArrayTypeNode
{
use AttributeTrait;
public function __toString(): string
{
if ($this->type instanceof CallableTypeNode) {

View File

@ -5,15 +5,14 @@ declare(strict_types=1);
namespace Rector\AttributeAwarePhpDoc\Ast\Type;
use Nette\Utils\Strings;
use PHPStan\PhpDocParser\Ast\NodeAttributes;
use PHPStan\PhpDocParser\Ast\Type\CallableTypeNode;
use PHPStan\PhpDocParser\Ast\Type\GenericTypeNode;
use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode;
use Rector\BetterPhpDocParser\Attributes\Attribute\AttributeTrait;
use Rector\BetterPhpDocParser\Contract\PhpDocNode\AttributeAwareNodeInterface;
final class AttributeAwareCallableTypeNode extends CallableTypeNode implements AttributeAwareNodeInterface
final class AttributeAwareCallableTypeNode extends CallableTypeNode
{
use AttributeTrait;
use NodeAttributes;
public function __toString(): string
{

View File

@ -1,14 +0,0 @@
<?php
declare(strict_types=1);
namespace Rector\AttributeAwarePhpDoc\Ast\Type;
use PHPStan\PhpDocParser\Ast\Type\CallableTypeParameterNode;
use Rector\BetterPhpDocParser\Attributes\Attribute\AttributeTrait;
use Rector\BetterPhpDocParser\Contract\PhpDocNode\AttributeAwareNodeInterface;
final class AttributeAwareCallableTypeParameterNode extends CallableTypeParameterNode implements AttributeAwareNodeInterface
{
use AttributeTrait;
}

View File

@ -1,14 +0,0 @@
<?php
declare(strict_types=1);
namespace Rector\AttributeAwarePhpDoc\Ast\Type;
use PHPStan\PhpDocParser\Ast\Type\ConstTypeNode;
use Rector\BetterPhpDocParser\Attributes\Attribute\AttributeTrait;
use Rector\BetterPhpDocParser\Contract\PhpDocNode\AttributeAwareNodeInterface;
final class AttributeAwareConstTypeNode extends ConstTypeNode implements AttributeAwareNodeInterface
{
use AttributeTrait;
}

View File

@ -1,24 +0,0 @@
<?php
declare(strict_types=1);
namespace Rector\AttributeAwarePhpDoc\Ast\Type;
use PHPStan\PhpDocParser\Ast\Type\GenericTypeNode;
use Rector\BetterPhpDocParser\Attributes\Attribute\AttributeTrait;
use Rector\BetterPhpDocParser\Contract\PhpDocNode\AttributeAwareNodeInterface;
use Rector\BetterPhpDocParser\Contract\PhpDocNode\TypeAwareTagValueNodeInterface;
final class AttributeAwareGenericTypeNode extends GenericTypeNode implements AttributeAwareNodeInterface, TypeAwareTagValueNodeInterface
{
use AttributeTrait;
public function __toString(): string
{
if ($this->genericTypes !== []) {
return parent::__toString();
}
return (string) $this->type;
}
}

View File

@ -1,14 +0,0 @@
<?php
declare(strict_types=1);
namespace Rector\AttributeAwarePhpDoc\Ast\Type;
use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode;
use Rector\BetterPhpDocParser\Attributes\Attribute\AttributeTrait;
use Rector\BetterPhpDocParser\Contract\PhpDocNode\AttributeAwareNodeInterface;
final class AttributeAwareIdentifierTypeNode extends IdentifierTypeNode implements AttributeAwareNodeInterface
{
use AttributeTrait;
}

View File

@ -5,13 +5,9 @@ declare(strict_types=1);
namespace Rector\AttributeAwarePhpDoc\Ast\Type;
use PHPStan\PhpDocParser\Ast\Type\IntersectionTypeNode;
use Rector\BetterPhpDocParser\Attributes\Attribute\AttributeTrait;
use Rector\BetterPhpDocParser\Contract\PhpDocNode\AttributeAwareNodeInterface;
final class AttributeAwareIntersectionTypeNode extends IntersectionTypeNode implements AttributeAwareNodeInterface
final class AttributeAwareIntersectionTypeNode extends IntersectionTypeNode
{
use AttributeTrait;
public function __toString(): string
{
return implode('&', $this->types);

View File

@ -1,14 +0,0 @@
<?php
declare(strict_types=1);
namespace Rector\AttributeAwarePhpDoc\Ast\Type;
use PHPStan\PhpDocParser\Ast\Type\NullableTypeNode;
use Rector\BetterPhpDocParser\Attributes\Attribute\AttributeTrait;
use Rector\BetterPhpDocParser\Contract\PhpDocNode\AttributeAwareNodeInterface;
final class AttributeAwareNullableTypeNode extends NullableTypeNode implements AttributeAwareNodeInterface
{
use AttributeTrait;
}

View File

@ -1,14 +0,0 @@
<?php
declare(strict_types=1);
namespace Rector\AttributeAwarePhpDoc\Ast\Type;
use PHPStan\PhpDocParser\Ast\Type\ThisTypeNode;
use Rector\BetterPhpDocParser\Attributes\Attribute\AttributeTrait;
use Rector\BetterPhpDocParser\Contract\PhpDocNode\AttributeAwareNodeInterface;
final class AttributeAwareThisTypeNode extends ThisTypeNode implements AttributeAwareNodeInterface
{
use AttributeTrait;
}

View File

@ -7,13 +7,9 @@ namespace Rector\AttributeAwarePhpDoc\Ast\Type;
use Nette\Utils\Strings;
use PHPStan\PhpDocParser\Ast\Type\TypeNode;
use PHPStan\PhpDocParser\Ast\Type\UnionTypeNode;
use Rector\BetterPhpDocParser\Attributes\Attribute\AttributeTrait;
use Rector\BetterPhpDocParser\Contract\PhpDocNode\AttributeAwareNodeInterface;
final class AttributeAwareUnionTypeNode extends UnionTypeNode implements AttributeAwareNodeInterface
final class AttributeAwareUnionTypeNode extends UnionTypeNode
{
use AttributeTrait;
/**
* @var string
* @see https://regex101.com/r/Hwk7Cg/1

View File

@ -0,0 +1,21 @@
<?php
declare(strict_types=1);
namespace Rector\AttributeAwarePhpDoc\Ast\Type;
use PHPStan\PhpDocParser\Ast\Type\GenericTypeNode;
use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode;
final class EmptyGenericTypeNode extends GenericTypeNode
{
public function __construct(IdentifierTypeNode $identifierTypeNode)
{
parent::__construct($identifierTypeNode, []);
}
public function __toString(): string
{
return (string) $this->type;
}
}

View File

@ -5,13 +5,9 @@ declare(strict_types=1);
namespace Rector\AttributeAwarePhpDoc\Ast\Type;
use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode;
use Rector\BetterPhpDocParser\Attributes\Attribute\AttributeTrait;
use Rector\BetterPhpDocParser\Contract\PhpDocNode\AttributeAwareNodeInterface;
final class FullyQualifiedIdentifierTypeNode extends IdentifierTypeNode implements AttributeAwareNodeInterface
final class FullyQualifiedIdentifierTypeNode extends IdentifierTypeNode
{
use AttributeTrait;
public function __toString(): string
{
return '\\' . $this->name;

View File

@ -1,32 +0,0 @@
<?php
declare(strict_types=1);
namespace Rector\AttributeAwarePhpDoc\AttributeAwareNodeFactory\PhpDoc;
use PHPStan\PhpDocParser\Ast\Node;
use PHPStan\PhpDocParser\Ast\PhpDoc\DeprecatedTagValueNode;
use Rector\AttributeAwarePhpDoc\Ast\PhpDoc\AttributeAwareDeprecatedTagValueNode;
use Rector\AttributeAwarePhpDoc\Contract\AttributeNodeAwareFactory\AttributeNodeAwareFactoryInterface;
use Rector\BetterPhpDocParser\Contract\PhpDocNode\AttributeAwareNodeInterface;
final class AttributeAwareDeprecatedTagValueNodeFactory implements AttributeNodeAwareFactoryInterface
{
public function getOriginalNodeClass(): string
{
return DeprecatedTagValueNode::class;
}
public function isMatch(Node $node): bool
{
return is_a($node, DeprecatedTagValueNode::class, true);
}
/**
* @param DeprecatedTagValueNode $node
*/
public function create(Node $node, string $docContent): AttributeAwareNodeInterface
{
return new AttributeAwareDeprecatedTagValueNode($node->description);
}
}

View File

@ -1,46 +0,0 @@
<?php
declare(strict_types=1);
namespace Rector\AttributeAwarePhpDoc\AttributeAwareNodeFactory\PhpDoc;
use PHPStan\PhpDocParser\Ast\Node;
use PHPStan\PhpDocParser\Ast\PhpDoc\ExtendsTagValueNode;
use Rector\AttributeAwarePhpDoc\Ast\PhpDoc\AttributeAwareExtendsTagValueNode;
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 AttributeAwareExtendsTagValueNodeFactory implements AttributeNodeAwareFactoryInterface, AttributeAwareNodeFactoryAwareInterface
{
/**
* @var AttributeAwareNodeFactory
*/
private $attributeAwareNodeFactory;
public function getOriginalNodeClass(): string
{
return ExtendsTagValueNode::class;
}
public function isMatch(Node $node): bool
{
return is_a($node, ExtendsTagValueNode::class, true);
}
/**
* @param ExtendsTagValueNode $node
*/
public function create(Node $node, string $docContent): AttributeAwareNodeInterface
{
$node->type = $this->attributeAwareNodeFactory->createFromNode($node->type, $docContent);
return new AttributeAwareExtendsTagValueNode($node->type, $node->description);
}
public function setAttributeAwareNodeFactory(AttributeAwareNodeFactory $attributeAwareNodeFactory): void
{
$this->attributeAwareNodeFactory = $attributeAwareNodeFactory;
}
}

View File

@ -1,32 +0,0 @@
<?php
declare(strict_types=1);
namespace Rector\AttributeAwarePhpDoc\AttributeAwareNodeFactory\PhpDoc;
use PHPStan\PhpDocParser\Ast\Node;
use PHPStan\PhpDocParser\Ast\PhpDoc\GenericTagValueNode;
use Rector\AttributeAwarePhpDoc\Ast\PhpDoc\AttributeAwareGenericTagValueNode;
use Rector\AttributeAwarePhpDoc\Contract\AttributeNodeAwareFactory\AttributeNodeAwareFactoryInterface;
use Rector\BetterPhpDocParser\Contract\PhpDocNode\AttributeAwareNodeInterface;
final class AttributeAwareGenericTagValueNodeFactory implements AttributeNodeAwareFactoryInterface
{
public function getOriginalNodeClass(): string
{
return GenericTagValueNode::class;
}
public function isMatch(Node $node): bool
{
return is_a($node, GenericTagValueNode::class, true);
}
/**
* @param GenericTagValueNode $node
*/
public function create(Node $node, string $docContent): AttributeAwareNodeInterface
{
return new AttributeAwareGenericTagValueNode($node->value);
}
}

View File

@ -1,46 +0,0 @@
<?php
declare(strict_types=1);
namespace Rector\AttributeAwarePhpDoc\AttributeAwareNodeFactory\PhpDoc;
use PHPStan\PhpDocParser\Ast\Node;
use PHPStan\PhpDocParser\Ast\PhpDoc\ImplementsTagValueNode;
use Rector\AttributeAwarePhpDoc\Ast\PhpDoc\AttributeAwareImplementsTagValueNode;
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 AttributeAwareImplementsTagValueNodeFactory implements AttributeNodeAwareFactoryInterface, AttributeAwareNodeFactoryAwareInterface
{
/**
* @var AttributeAwareNodeFactory
*/
private $attributeAwareNodeFactory;
public function getOriginalNodeClass(): string
{
return ImplementsTagValueNode::class;
}
public function isMatch(Node $node): bool
{
return is_a($node, ImplementsTagValueNode::class, true);
}
/**
* @param ImplementsTagValueNode $node
*/
public function create(Node $node, string $docContent): AttributeAwareNodeInterface
{
$node->type = $this->attributeAwareNodeFactory->createFromNode($node->type, $docContent);
return new AttributeAwareImplementsTagValueNode($node->type, $node->description);
}
public function setAttributeAwareNodeFactory(AttributeAwareNodeFactory $attributeAwareNodeFactory): void
{
$this->attributeAwareNodeFactory = $attributeAwareNodeFactory;
}
}

View File

@ -1,32 +0,0 @@
<?php
declare(strict_types=1);
namespace Rector\AttributeAwarePhpDoc\AttributeAwareNodeFactory\PhpDoc;
use PHPStan\PhpDocParser\Ast\Node;
use PHPStan\PhpDocParser\Ast\PhpDoc\InvalidTagValueNode;
use Rector\AttributeAwarePhpDoc\Ast\PhpDoc\AttributeAwareInvalidTagValueNode;
use Rector\AttributeAwarePhpDoc\Contract\AttributeNodeAwareFactory\AttributeNodeAwareFactoryInterface;
use Rector\BetterPhpDocParser\Contract\PhpDocNode\AttributeAwareNodeInterface;
final class AttributeAwareInvalidTagValueNodeFactory implements AttributeNodeAwareFactoryInterface
{
public function getOriginalNodeClass(): string
{
return InvalidTagValueNode::class;
}
public function isMatch(Node $node): bool
{
return is_a($node, InvalidTagValueNode::class, true);
}
/**
* @param InvalidTagValueNode $node
*/
public function create(Node $node, string $docContent): AttributeAwareNodeInterface
{
return new AttributeAwareInvalidTagValueNode($node->value, $node->exception);
}
}

View File

@ -1,73 +0,0 @@
<?php
declare(strict_types=1);
namespace Rector\AttributeAwarePhpDoc\AttributeAwareNodeFactory\PhpDoc;
use PHPStan\PhpDocParser\Ast\Node;
use PHPStan\PhpDocParser\Ast\PhpDoc\MethodTagValueNode;
use PHPStan\PhpDocParser\Ast\Type\TypeNode;
use Rector\AttributeAwarePhpDoc\Ast\PhpDoc\AttributeAwareMethodTagValueNode;
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 AttributeAwareMethodTagValueNodeFactory implements AttributeNodeAwareFactoryInterface, AttributeAwareNodeFactoryAwareInterface
{
/**
* @var AttributeAwareNodeFactory
*/
private $attributeAwareNodeFactory;
public function getOriginalNodeClass(): string
{
return MethodTagValueNode::class;
}
public function isMatch(Node $node): bool
{
return is_a($node, MethodTagValueNode::class, true);
}
/**
* @param MethodTagValueNode $node
*/
public function create(Node $node, string $docContent): AttributeAwareNodeInterface
{
$returnType = $this->attributizeReturnType($node, $docContent);
foreach ($node->parameters as $key => $parameter) {
$node->parameters[$key] = $this->attributeAwareNodeFactory->createFromNode($parameter, $docContent);
}
return new AttributeAwareMethodTagValueNode(
$node->isStatic,
$returnType,
$node->methodName,
$node->parameters,
$node->description
);
}
public function setAttributeAwareNodeFactory(AttributeAwareNodeFactory $attributeAwareNodeFactory): void
{
$this->attributeAwareNodeFactory = $attributeAwareNodeFactory;
}
private function attributizeReturnType(
MethodTagValueNode $methodTagValueNode,
string $docContent
): ?AttributeAwareNodeInterface {
if ($methodTagValueNode->returnType !== null) {
return $this->createAttributeAwareReturnType($methodTagValueNode->returnType, $docContent);
}
return null;
}
private function createAttributeAwareReturnType(TypeNode $typeNode, string $docContent): AttributeAwareNodeInterface
{
return $this->attributeAwareNodeFactory->createFromNode($typeNode, $docContent);
}
}

View File

@ -1,54 +0,0 @@
<?php
declare(strict_types=1);
namespace Rector\AttributeAwarePhpDoc\AttributeAwareNodeFactory\PhpDoc;
use PHPStan\PhpDocParser\Ast\Node;
use PHPStan\PhpDocParser\Ast\PhpDoc\MethodTagValueParameterNode;
use Rector\AttributeAwarePhpDoc\Ast\PhpDoc\AttributeAwareMethodTagValueParameterNode;
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 AttributeAwareMethodTagValueParameterNodeFactory implements AttributeNodeAwareFactoryInterface, AttributeAwareNodeFactoryAwareInterface
{
/**
* @var AttributeAwareNodeFactory
*/
private $attributeAwareNodeFactory;
public function getOriginalNodeClass(): string
{
return MethodTagValueParameterNode::class;
}
public function isMatch(Node $node): bool
{
return is_a($node, MethodTagValueParameterNode::class, true);
}
/**
* @param MethodTagValueParameterNode $node
*/
public function create(Node $node, string $docContent): AttributeAwareNodeInterface
{
if ($node->type !== null) {
$node->type = $this->attributeAwareNodeFactory->createFromNode($node->type, $docContent);
}
return new AttributeAwareMethodTagValueParameterNode(
$node->type,
$node->isReference,
$node->isVariadic,
$node->parameterName,
$node->defaultValue
);
}
public function setAttributeAwareNodeFactory(AttributeAwareNodeFactory $attributeAwareNodeFactory): void
{
$this->attributeAwareNodeFactory = $attributeAwareNodeFactory;
}
}

View File

@ -1,32 +0,0 @@
<?php
declare(strict_types=1);
namespace Rector\AttributeAwarePhpDoc\AttributeAwareNodeFactory\PhpDoc;
use PHPStan\PhpDocParser\Ast\Node;
use PHPStan\PhpDocParser\Ast\PhpDoc\MixinTagValueNode;
use Rector\AttributeAwarePhpDoc\Ast\PhpDoc\AttributeAwareMixinTagValueNode;
use Rector\AttributeAwarePhpDoc\Contract\AttributeNodeAwareFactory\AttributeNodeAwareFactoryInterface;
use Rector\BetterPhpDocParser\Contract\PhpDocNode\AttributeAwareNodeInterface;
final class AttributeAwareMixinTagValueNodeFactory implements AttributeNodeAwareFactoryInterface
{
public function getOriginalNodeClass(): string
{
return MixinTagValueNode::class;
}
public function isMatch(Node $node): bool
{
return is_a($node, MixinTagValueNode::class, true);
}
/**
* @param MixinTagValueNode $node
*/
public function create(Node $node, string $docContent): AttributeAwareNodeInterface
{
return new AttributeAwareMixinTagValueNode($node->type, $node->description);
}
}

View File

@ -10,7 +10,6 @@ use Rector\AttributeAwarePhpDoc\Ast\PhpDoc\AttributeAwareParamTagValueNode;
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 AttributeAwareParamTagValueNodeFactory implements AttributeNodeAwareFactoryInterface, AttributeAwareNodeFactoryAwareInterface
{
@ -19,11 +18,6 @@ final class AttributeAwareParamTagValueNodeFactory implements AttributeNodeAware
*/
private $attributeAwareNodeFactory;
public function getOriginalNodeClass(): string
{
return ParamTagValueNode::class;
}
public function isMatch(Node $node): bool
{
return is_a($node, ParamTagValueNode::class, true);
@ -31,8 +25,9 @@ final class AttributeAwareParamTagValueNodeFactory implements AttributeNodeAware
/**
* @param ParamTagValueNode $node
* @return AttributeAwareParamTagValueNode
*/
public function create(Node $node, string $docContent): AttributeAwareNodeInterface
public function create(Node $node, string $docContent): Node
{
$node->type = $this->attributeAwareNodeFactory->createFromNode($node->type, $docContent);

View File

@ -10,7 +10,7 @@ use Rector\AttributeAwarePhpDoc\Ast\PhpDoc\AttributeAwarePhpDocNode;
use Rector\AttributeAwarePhpDoc\Contract\AttributeNodeAwareFactory\AttributeAwareNodeFactoryAwareInterface;
use Rector\AttributeAwarePhpDoc\Contract\AttributeNodeAwareFactory\AttributeNodeAwareFactoryInterface;
use Rector\BetterPhpDocParser\Attributes\Ast\AttributeAwareNodeFactory;
use Rector\BetterPhpDocParser\Contract\PhpDocNode\AttributeAwareNodeInterface;
use Symplify\SimplePhpDocParser\PhpDocNodeTraverser;
final class AttributeAwarePhpDocNodeFactory implements AttributeNodeAwareFactoryInterface, AttributeAwareNodeFactoryAwareInterface
@ -30,11 +30,6 @@ final class AttributeAwarePhpDocNodeFactory implements AttributeNodeAwareFactory
$this->phpDocNodeTraverser = $phpDocNodeTraverser;
}
public function getOriginalNodeClass(): string
{
return PhpDocNode::class;
}
public function isMatch(Node $node): bool
{
return is_a($node, PhpDocNode::class, true);
@ -43,15 +38,11 @@ final class AttributeAwarePhpDocNodeFactory implements AttributeNodeAwareFactory
/**
* @param PhpDocNode $node
*/
public function create(Node $node, string $docContent): AttributeAwareNodeInterface
public function create(Node $node, string $docContent): Node
{
$this->phpDocNodeTraverser->traverseWithCallable($node, $docContent, function (Node $node) use (
$docContent
): AttributeAwareNodeInterface {
if ($node instanceof AttributeAwareNodeInterface) {
return $node;
}
): Node {
return $this->attributeAwareNodeFactory->createFromNode($node, $docContent);
});

View File

@ -1,32 +0,0 @@
<?php
declare(strict_types=1);
namespace Rector\AttributeAwarePhpDoc\AttributeAwareNodeFactory\PhpDoc;
use PHPStan\PhpDocParser\Ast\Node;
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode;
use Rector\AttributeAwarePhpDoc\Ast\PhpDoc\AttributeAwarePhpDocTagNode;
use Rector\AttributeAwarePhpDoc\Contract\AttributeNodeAwareFactory\AttributeNodeAwareFactoryInterface;
use Rector\BetterPhpDocParser\Contract\PhpDocNode\AttributeAwareNodeInterface;
final class AttributeAwarePhpDocTagNodeFactory implements AttributeNodeAwareFactoryInterface
{
public function getOriginalNodeClass(): string
{
return PhpDocTagNode::class;
}
public function isMatch(Node $node): bool
{
return is_a($node, PhpDocTagNode::class, true);
}
/**
* @param PhpDocTagNode $node
*/
public function create(Node $node, string $docContent): AttributeAwareNodeInterface
{
return new AttributeAwarePhpDocTagNode($node->name, $node->value);
}
}

View File

@ -1,32 +0,0 @@
<?php
declare(strict_types=1);
namespace Rector\AttributeAwarePhpDoc\AttributeAwareNodeFactory\PhpDoc;
use PHPStan\PhpDocParser\Ast\Node;
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTextNode;
use Rector\AttributeAwarePhpDoc\Ast\PhpDoc\AttributeAwarePhpDocTextNode;
use Rector\AttributeAwarePhpDoc\Contract\AttributeNodeAwareFactory\AttributeNodeAwareFactoryInterface;
use Rector\BetterPhpDocParser\Contract\PhpDocNode\AttributeAwareNodeInterface;
final class AttributeAwarePhpDocTextNodeFactory implements AttributeNodeAwareFactoryInterface
{
public function getOriginalNodeClass(): string
{
return PhpDocTextNode::class;
}
public function isMatch(Node $node): bool
{
return is_a($node, PhpDocTextNode::class, true);
}
/**
* @param PhpDocTextNode $node
*/
public function create(Node $node, string $docContent): AttributeAwareNodeInterface
{
return new AttributeAwarePhpDocTextNode($node->text);
}
}

View File

@ -1,46 +0,0 @@
<?php
declare(strict_types=1);
namespace Rector\AttributeAwarePhpDoc\AttributeAwareNodeFactory\PhpDoc;
use PHPStan\PhpDocParser\Ast\Node;
use PHPStan\PhpDocParser\Ast\PhpDoc\PropertyTagValueNode;
use Rector\AttributeAwarePhpDoc\Ast\PhpDoc\AttributeAwarePropertyTagValueNode;
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 AttributeAwarePropertyTagValueNodeFactory implements AttributeNodeAwareFactoryInterface, AttributeAwareNodeFactoryAwareInterface
{
/**
* @var AttributeAwareNodeFactory
*/
private $attributeAwareNodeFactory;
public function getOriginalNodeClass(): string
{
return PropertyTagValueNode::class;
}
public function isMatch(Node $node): bool
{
return is_a($node, PropertyTagValueNode::class, true);
}
/**
* @param PropertyTagValueNode $node
*/
public function create(Node $node, string $docContent): AttributeAwareNodeInterface
{
$node->type = $this->attributeAwareNodeFactory->createFromNode($node->type, $docContent);
return new AttributeAwarePropertyTagValueNode($node->type, $node->propertyName, $node->description);
}
public function setAttributeAwareNodeFactory(AttributeAwareNodeFactory $attributeAwareNodeFactory): void
{
$this->attributeAwareNodeFactory = $attributeAwareNodeFactory;
}
}

View File

@ -1,46 +0,0 @@
<?php
declare(strict_types=1);
namespace Rector\AttributeAwarePhpDoc\AttributeAwareNodeFactory\PhpDoc;
use PHPStan\PhpDocParser\Ast\Node;
use PHPStan\PhpDocParser\Ast\PhpDoc\ReturnTagValueNode;
use Rector\AttributeAwarePhpDoc\Ast\PhpDoc\AttributeAwareReturnTagValueNode;
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 AttributeAwareReturnTagValueNodeFactory implements AttributeNodeAwareFactoryInterface, AttributeAwareNodeFactoryAwareInterface
{
/**
* @var AttributeAwareNodeFactory
*/
private $attributeAwareNodeFactory;
public function getOriginalNodeClass(): string
{
return ReturnTagValueNode::class;
}
public function isMatch(Node $node): bool
{
return is_a($node, ReturnTagValueNode::class, true);
}
/**
* @param ReturnTagValueNode $node
*/
public function create(Node $node, string $docContent): AttributeAwareNodeInterface
{
$node->type = $this->attributeAwareNodeFactory->createFromNode($node->type, $docContent);
return new AttributeAwareReturnTagValueNode($node->type, $node->description);
}
public function setAttributeAwareNodeFactory(AttributeAwareNodeFactory $attributeAwareNodeFactory): void
{
$this->attributeAwareNodeFactory = $attributeAwareNodeFactory;
}
}

View File

@ -8,15 +8,9 @@ use PHPStan\PhpDocParser\Ast\Node;
use PHPStan\PhpDocParser\Ast\PhpDoc\TemplateTagValueNode;
use Rector\AttributeAwarePhpDoc\Ast\PhpDoc\AttributeAwareTemplateTagValueNode;
use Rector\AttributeAwarePhpDoc\Contract\AttributeNodeAwareFactory\AttributeNodeAwareFactoryInterface;
use Rector\BetterPhpDocParser\Contract\PhpDocNode\AttributeAwareNodeInterface;
final class AttributeAwareTemplateTagValueNodeFactory implements AttributeNodeAwareFactoryInterface
{
public function getOriginalNodeClass(): string
{
return TemplateTagValueNode::class;
}
public function isMatch(Node $node): bool
{
return is_a($node, TemplateTagValueNode::class, true);
@ -25,7 +19,7 @@ final class AttributeAwareTemplateTagValueNodeFactory implements AttributeNodeAw
/**
* @param TemplateTagValueNode $node
*/
public function create(Node $node, string $docContent): AttributeAwareNodeInterface
public function create(Node $node, string $docContent): Node
{
return new AttributeAwareTemplateTagValueNode($node->name, $node->bound, $node->description, $docContent);
}

View File

@ -1,46 +0,0 @@
<?php
declare(strict_types=1);
namespace Rector\AttributeAwarePhpDoc\AttributeAwareNodeFactory\PhpDoc;
use PHPStan\PhpDocParser\Ast\Node;
use PHPStan\PhpDocParser\Ast\PhpDoc\ThrowsTagValueNode;
use Rector\AttributeAwarePhpDoc\Ast\PhpDoc\AttributeAwareThrowsTagValueNode;
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 AttributeAwareThrowsTagValueNodeFactory implements AttributeNodeAwareFactoryInterface, AttributeAwareNodeFactoryAwareInterface
{
/**
* @var AttributeAwareNodeFactory
*/
private $attributeAwareNodeFactory;
public function getOriginalNodeClass(): string
{
return ThrowsTagValueNode::class;
}
public function isMatch(Node $node): bool
{
return is_a($node, ThrowsTagValueNode::class, true);
}
/**
* @param ThrowsTagValueNode $node
*/
public function create(Node $node, string $docContent): AttributeAwareNodeInterface
{
$node->type = $this->attributeAwareNodeFactory->createFromNode($node->type, $docContent);
return new AttributeAwareThrowsTagValueNode($node->type, $node->description);
}
public function setAttributeAwareNodeFactory(AttributeAwareNodeFactory $attributeAwareNodeFactory): void
{
$this->attributeAwareNodeFactory = $attributeAwareNodeFactory;
}
}

View File

@ -1,32 +0,0 @@
<?php
declare(strict_types=1);
namespace Rector\AttributeAwarePhpDoc\AttributeAwareNodeFactory\PhpDoc;
use PHPStan\PhpDocParser\Ast\Node;
use PHPStan\PhpDocParser\Ast\PhpDoc\UsesTagValueNode;
use Rector\AttributeAwarePhpDoc\Ast\PhpDoc\AttributeAwareUsesTagValueNode;
use Rector\AttributeAwarePhpDoc\Contract\AttributeNodeAwareFactory\AttributeNodeAwareFactoryInterface;
use Rector\BetterPhpDocParser\Contract\PhpDocNode\AttributeAwareNodeInterface;
final class AttributeAwareUsesTagValueNodeFactory implements AttributeNodeAwareFactoryInterface
{
public function getOriginalNodeClass(): string
{
return UsesTagValueNode::class;
}
public function isMatch(Node $node): bool
{
return is_a($node, UsesTagValueNode::class, true);
}
/**
* @param UsesTagValueNode $node
*/
public function create(Node $node, string $docContent): AttributeAwareNodeInterface
{
return new AttributeAwareUsesTagValueNode($node->type, $node->description);
}
}

View File

@ -1,46 +0,0 @@
<?php
declare(strict_types=1);
namespace Rector\AttributeAwarePhpDoc\AttributeAwareNodeFactory\PhpDoc;
use PHPStan\PhpDocParser\Ast\Node;
use PHPStan\PhpDocParser\Ast\PhpDoc\VarTagValueNode;
use Rector\AttributeAwarePhpDoc\Ast\PhpDoc\AttributeAwareVarTagValueNode;
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 AttributeAwareVarTagValueNodeFactory implements AttributeNodeAwareFactoryInterface, AttributeAwareNodeFactoryAwareInterface
{
/**
* @var AttributeAwareNodeFactory
*/
private $attributeAwareNodeFactory;
public function getOriginalNodeClass(): string
{
return VarTagValueNode::class;
}
public function isMatch(Node $node): bool
{
return is_a($node, VarTagValueNode::class, true);
}
/**
* @param VarTagValueNode $node
*/
public function create(Node $node, string $docContent): AttributeAwareNodeInterface
{
$node->type = $this->attributeAwareNodeFactory->createFromNode($node->type, $docContent);
return new AttributeAwareVarTagValueNode($node->type, $node->variableName, $node->description);
}
public function setAttributeAwareNodeFactory(AttributeAwareNodeFactory $attributeAwareNodeFactory): void
{
$this->attributeAwareNodeFactory = $attributeAwareNodeFactory;
}
}

View File

@ -10,7 +10,6 @@ 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, AttributeAwareNodeFactoryAwareInterface
{
@ -19,11 +18,6 @@ final class AttributeAwareArrayShapeItemNodeFactory implements AttributeNodeAwar
*/
private $attributeAwareNodeFactory;
public function getOriginalNodeClass(): string
{
return ArrayShapeItemNode::class;
}
public function isMatch(Node $node): bool
{
return is_a($node, ArrayShapeItemNode::class, true);
@ -31,8 +25,9 @@ final class AttributeAwareArrayShapeItemNodeFactory implements AttributeNodeAwar
/**
* @param ArrayShapeItemNode $node
* @return AttributeAwareArrayShapeItemNode
*/
public function create(Node $node, string $docContent): AttributeAwareNodeInterface
public function create(Node $node, string $docContent): Node
{
$node->valueType = $this->attributeAwareNodeFactory->createFromNode($node->valueType, $docContent);
return new AttributeAwareArrayShapeItemNode($node->keyName, $node->optional, $node->valueType, $docContent);

View File

@ -1,49 +0,0 @@
<?php
declare(strict_types=1);
namespace Rector\AttributeAwarePhpDoc\AttributeAwareNodeFactory\Type;
use PHPStan\PhpDocParser\Ast\Node;
use PHPStan\PhpDocParser\Ast\Type\ArrayShapeNode;
use Rector\AttributeAwarePhpDoc\Ast\Type\AttributeAwareArrayShapeNode;
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 AttributeAwareArrayShapeNodeFactory implements AttributeNodeAwareFactoryInterface, AttributeAwareNodeFactoryAwareInterface
{
/**
* @var AttributeAwareNodeFactory
*/
private $attributeAwareNodeFactory;
public function getOriginalNodeClass(): string
{
return ArrayShapeNode::class;
}
public function isMatch(Node $node): bool
{
return is_a($node, ArrayShapeNode::class, true);
}
/**
* @param ArrayShapeNode $node
*/
public function create(Node $node, string $docContent): AttributeAwareNodeInterface
{
$items = [];
foreach ($node->items as $item) {
$items[] = $this->attributeAwareNodeFactory->createFromNode($item, $docContent);
}
return new AttributeAwareArrayShapeNode($items);
}
public function setAttributeAwareNodeFactory(AttributeAwareNodeFactory $attributeAwareNodeFactory): void
{
$this->attributeAwareNodeFactory = $attributeAwareNodeFactory;
}
}

View File

@ -10,7 +10,6 @@ use Rector\AttributeAwarePhpDoc\Ast\Type\AttributeAwareArrayTypeNode;
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 AttributeAwareArrayTypeNodeFactory implements AttributeNodeAwareFactoryInterface, AttributeAwareNodeFactoryAwareInterface
{
@ -19,11 +18,6 @@ final class AttributeAwareArrayTypeNodeFactory implements AttributeNodeAwareFact
*/
private $attributeAwareNodeFactory;
public function getOriginalNodeClass(): string
{
return ArrayTypeNode::class;
}
public function isMatch(Node $node): bool
{
return is_a($node, ArrayTypeNode::class, true);
@ -31,8 +25,9 @@ final class AttributeAwareArrayTypeNodeFactory implements AttributeNodeAwareFact
/**
* @param ArrayTypeNode $node
* @return AttributeAwareArrayTypeNode
*/
public function create(Node $node, string $docContent): AttributeAwareNodeInterface
public function create(Node $node, string $docContent): Node
{
$node->type = $this->attributeAwareNodeFactory->createFromNode($node->type, $docContent);

View File

@ -10,7 +10,6 @@ use Rector\AttributeAwarePhpDoc\Ast\Type\AttributeAwareCallableTypeNode;
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 AttributeAwareCallableTypeNodeFactory implements AttributeNodeAwareFactoryInterface, AttributeAwareNodeFactoryAwareInterface
{
@ -19,11 +18,6 @@ final class AttributeAwareCallableTypeNodeFactory implements AttributeNodeAwareF
*/
private $attributeAwareNodeFactory;
public function getOriginalNodeClass(): string
{
return CallableTypeNode::class;
}
public function isMatch(Node $node): bool
{
return is_a($node, CallableTypeNode::class, true);
@ -31,8 +25,9 @@ final class AttributeAwareCallableTypeNodeFactory implements AttributeNodeAwareF
/**
* @param CallableTypeNode $node
* @return AttributeAwareCallableTypeNode
*/
public function create(Node $node, string $docContent): AttributeAwareNodeInterface
public function create(Node $node, string $docContent): Node
{
$identifier = $this->attributeAwareNodeFactory->createFromNode($node->identifier, $docContent);

View File

@ -1,38 +0,0 @@
<?php
declare(strict_types=1);
namespace Rector\AttributeAwarePhpDoc\AttributeAwareNodeFactory\Type;
use PHPStan\PhpDocParser\Ast\Node;
use PHPStan\PhpDocParser\Ast\Type\CallableTypeParameterNode;
use Rector\AttributeAwarePhpDoc\Ast\Type\AttributeAwareCallableTypeParameterNode;
use Rector\AttributeAwarePhpDoc\Contract\AttributeNodeAwareFactory\AttributeNodeAwareFactoryInterface;
use Rector\BetterPhpDocParser\Contract\PhpDocNode\AttributeAwareNodeInterface;
final class AttributeAwareCallableTypeParameterNodeFactory implements AttributeNodeAwareFactoryInterface
{
public function getOriginalNodeClass(): string
{
return CallableTypeParameterNode::class;
}
public function isMatch(Node $node): bool
{
return is_a($node, CallableTypeParameterNode::class, true);
}
/**
* @param CallableTypeParameterNode $node
*/
public function create(Node $node, string $docContent): AttributeAwareNodeInterface
{
return new AttributeAwareCallableTypeParameterNode(
$node->type,
$node->isReference,
$node->isVariadic,
$node->parameterName,
$node->isOptional
);
}
}

View File

@ -1,32 +0,0 @@
<?php
declare(strict_types=1);
namespace Rector\AttributeAwarePhpDoc\AttributeAwareNodeFactory\Type;
use PHPStan\PhpDocParser\Ast\Node;
use PHPStan\PhpDocParser\Ast\Type\ConstTypeNode;
use Rector\AttributeAwarePhpDoc\Ast\Type\AttributeAwareConstTypeNode;
use Rector\AttributeAwarePhpDoc\Contract\AttributeNodeAwareFactory\AttributeNodeAwareFactoryInterface;
use Rector\BetterPhpDocParser\Contract\PhpDocNode\AttributeAwareNodeInterface;
final class AttributeAwareConstTypeNodeFactory implements AttributeNodeAwareFactoryInterface
{
public function getOriginalNodeClass(): string
{
return ConstTypeNode::class;
}
public function isMatch(Node $node): bool
{
return is_a($node, ConstTypeNode::class, true);
}
/**
* @param ConstTypeNode $node
*/
public function create(Node $node, string $docContent): AttributeAwareNodeInterface
{
return new AttributeAwareConstTypeNode($node->constExpr);
}
}

View File

@ -1,51 +0,0 @@
<?php
declare(strict_types=1);
namespace Rector\AttributeAwarePhpDoc\AttributeAwareNodeFactory\Type;
use PHPStan\PhpDocParser\Ast\Node;
use PHPStan\PhpDocParser\Ast\Type\GenericTypeNode;
use Rector\AttributeAwarePhpDoc\Ast\Type\AttributeAwareGenericTypeNode;
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 AttributeAwareGenericTypeNodeFactory implements AttributeNodeAwareFactoryInterface, AttributeAwareNodeFactoryAwareInterface
{
/**
* @var AttributeAwareNodeFactory
*/
private $attributeAwareNodeFactory;
public function getOriginalNodeClass(): string
{
return GenericTypeNode::class;
}
public function isMatch(Node $node): bool
{
return is_a($node, GenericTypeNode::class, true);
}
/**
* @param GenericTypeNode $node
*/
public function create(Node $node, string $docContent): AttributeAwareNodeInterface
{
$node->type = $this->attributeAwareNodeFactory->createFromNode($node->type, $docContent);
$genericTypes = [];
foreach ($node->genericTypes as $genericType) {
$genericTypes[] = $this->attributeAwareNodeFactory->createFromNode($genericType, $docContent);
}
return new AttributeAwareGenericTypeNode($node->type, $genericTypes);
}
public function setAttributeAwareNodeFactory(AttributeAwareNodeFactory $attributeAwareNodeFactory): void
{
$this->attributeAwareNodeFactory = $attributeAwareNodeFactory;
}
}

View File

@ -1,32 +0,0 @@
<?php
declare(strict_types=1);
namespace Rector\AttributeAwarePhpDoc\AttributeAwareNodeFactory\Type;
use PHPStan\PhpDocParser\Ast\Node;
use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode;
use Rector\AttributeAwarePhpDoc\Ast\Type\AttributeAwareIdentifierTypeNode;
use Rector\AttributeAwarePhpDoc\Contract\AttributeNodeAwareFactory\AttributeNodeAwareFactoryInterface;
use Rector\BetterPhpDocParser\Contract\PhpDocNode\AttributeAwareNodeInterface;
final class AttributeAwareIdentifierTypeNodeFactory implements AttributeNodeAwareFactoryInterface
{
public function getOriginalNodeClass(): string
{
return IdentifierTypeNode::class;
}
public function isMatch(Node $node): bool
{
return is_a($node, IdentifierTypeNode::class, true);
}
/**
* @param IdentifierTypeNode $node
*/
public function create(Node $node, string $docContent): AttributeAwareNodeInterface
{
return new AttributeAwareIdentifierTypeNode($node->name);
}
}

View File

@ -10,7 +10,6 @@ use Rector\AttributeAwarePhpDoc\Ast\Type\AttributeAwareIntersectionTypeNode;
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 AttributeAwareIntersectionTypeNodeFactory implements AttributeNodeAwareFactoryInterface, AttributeAwareNodeFactoryAwareInterface
{
@ -19,11 +18,6 @@ final class AttributeAwareIntersectionTypeNodeFactory implements AttributeNodeAw
*/
private $attributeAwareNodeFactory;
public function getOriginalNodeClass(): string
{
return IntersectionTypeNode::class;
}
public function isMatch(Node $node): bool
{
return is_a($node, IntersectionTypeNode::class, true);
@ -32,7 +26,7 @@ final class AttributeAwareIntersectionTypeNodeFactory implements AttributeNodeAw
/**
* @param IntersectionTypeNode $node
*/
public function create(Node $node, string $docContent): AttributeAwareNodeInterface
public function create(Node $node, string $docContent): Node
{
foreach ($node->types as $key => $intersectionedType) {
$node->types[$key] = $this->attributeAwareNodeFactory->createFromNode($intersectionedType, $docContent);

View File

@ -1,46 +0,0 @@
<?php
declare(strict_types=1);
namespace Rector\AttributeAwarePhpDoc\AttributeAwareNodeFactory\Type;
use PHPStan\PhpDocParser\Ast\Node;
use PHPStan\PhpDocParser\Ast\Type\NullableTypeNode;
use Rector\AttributeAwarePhpDoc\Ast\Type\AttributeAwareNullableTypeNode;
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 AttributeAwareNullableTypeNodeFactory implements AttributeNodeAwareFactoryInterface, AttributeAwareNodeFactoryAwareInterface
{
/**
* @var AttributeAwareNodeFactory
*/
private $attributeAwareNodeFactory;
public function getOriginalNodeClass(): string
{
return NullableTypeNode::class;
}
public function isMatch(Node $node): bool
{
return is_a($node, NullableTypeNode::class, true);
}
/**
* @param NullableTypeNode $node
*/
public function create(Node $node, string $docContent): AttributeAwareNodeInterface
{
$node->type = $this->attributeAwareNodeFactory->createFromNode($node->type, $docContent);
return new AttributeAwareNullableTypeNode($node->type);
}
public function setAttributeAwareNodeFactory(AttributeAwareNodeFactory $attributeAwareNodeFactory): void
{
$this->attributeAwareNodeFactory = $attributeAwareNodeFactory;
}
}

View File

@ -1,32 +0,0 @@
<?php
declare(strict_types=1);
namespace Rector\AttributeAwarePhpDoc\AttributeAwareNodeFactory\Type;
use PHPStan\PhpDocParser\Ast\Node;
use PHPStan\PhpDocParser\Ast\Type\ThisTypeNode;
use Rector\AttributeAwarePhpDoc\Ast\Type\AttributeAwareThisTypeNode;
use Rector\AttributeAwarePhpDoc\Contract\AttributeNodeAwareFactory\AttributeNodeAwareFactoryInterface;
use Rector\BetterPhpDocParser\Contract\PhpDocNode\AttributeAwareNodeInterface;
final class AttributeAwareThisTypeNodeFactory implements AttributeNodeAwareFactoryInterface
{
public function getOriginalNodeClass(): string
{
return ThisTypeNode::class;
}
public function isMatch(Node $node): bool
{
return is_a($node, ThisTypeNode::class, true);
}
/**
* @param ThisTypeNode $node
*/
public function create(Node $node, string $docContent): AttributeAwareNodeInterface
{
return new AttributeAwareThisTypeNode();
}
}

View File

@ -1,48 +0,0 @@
<?php
declare(strict_types=1);
namespace Rector\AttributeAwarePhpDoc\AttributeAwareNodeFactory\Type;
use PHPStan\PhpDocParser\Ast\Node;
use PHPStan\PhpDocParser\Ast\Type\UnionTypeNode;
use Rector\AttributeAwarePhpDoc\Ast\Type\AttributeAwareUnionTypeNode;
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 AttributeAwareUnionTypeNodeFactory implements AttributeNodeAwareFactoryInterface, AttributeAwareNodeFactoryAwareInterface
{
/**
* @var AttributeAwareNodeFactory
*/
private $attributeAwareNodeFactory;
public function getOriginalNodeClass(): string
{
return UnionTypeNode::class;
}
public function isMatch(Node $node): bool
{
return is_a($node, UnionTypeNode::class, true);
}
/**
* @param UnionTypeNode $node
*/
public function create(Node $node, string $docContent): AttributeAwareNodeInterface
{
foreach ($node->types as $key => $unionedType) {
$node->types[$key] = $this->attributeAwareNodeFactory->createFromNode($unionedType, $docContent);
}
return new AttributeAwareUnionTypeNode($node->types, $docContent);
}
public function setAttributeAwareNodeFactory(AttributeAwareNodeFactory $attributeAwareNodeFactory): void
{
$this->attributeAwareNodeFactory = $attributeAwareNodeFactory;
}
}

View File

@ -1,44 +0,0 @@
<?php
declare(strict_types=1);
namespace Rector\AttributeAwarePhpDoc;
use Rector\AttributeAwarePhpDoc\Contract\AttributeNodeAwareFactory\AttributeNodeAwareFactoryInterface;
final class AttributeAwareNodeFactoryCollector
{
/**
* @var AttributeNodeAwareFactoryInterface[]
*/
private $attributeAwareNodeFactories = [];
/**
* @param AttributeNodeAwareFactoryInterface[] $attributeAwareNodeFactories
*/
public function __construct(array $attributeAwareNodeFactories)
{
$this->attributeAwareNodeFactories = $attributeAwareNodeFactories;
}
/**
* @return AttributeNodeAwareFactoryInterface[]
*/
public function provide(): array
{
return $this->attributeAwareNodeFactories;
}
/**
* @return string[]
*/
public function getSupportedNodeClasses(): array
{
$supportedNodeClasses = [];
foreach ($this->attributeAwareNodeFactories as $attributeAwareNodeFactory) {
$supportedNodeClasses[] = $attributeAwareNodeFactory->getOriginalNodeClass();
}
return $supportedNodeClasses;
}
}

View File

@ -5,13 +5,15 @@ declare(strict_types=1);
namespace Rector\AttributeAwarePhpDoc\Contract\AttributeNodeAwareFactory;
use PHPStan\PhpDocParser\Ast\Node;
use Rector\BetterPhpDocParser\Contract\PhpDocNode\AttributeAwareNodeInterface;
interface AttributeNodeAwareFactoryInterface
{
public function getOriginalNodeClass(): string;
public function isMatch(Node $node): bool;
public function create(Node $node, string $docContent): AttributeAwareNodeInterface;
/**
* @template T of Node
* @param T $node
* @return T
*/
public function create(Node $node, string $docContent): Node;
}

View File

@ -5,13 +5,14 @@ declare(strict_types=1);
namespace Rector\BetterPhpDocParser\Attributes\Ast;
use PHPStan\PhpDocParser\Ast\Node;
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocChildNode;
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocNode;
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagValueNode;
use Rector\AttributeAwarePhpDoc\AttributeAwareNodeFactoryCollector;
use PHPStan\PhpDocParser\Ast\Type\ArrayShapeItemNode;
use PHPStan\PhpDocParser\Ast\Type\UnionTypeNode;
use Rector\AttributeAwarePhpDoc\Ast\Type\AttributeAwareArrayShapeItemNode;
use Rector\AttributeAwarePhpDoc\Ast\Type\AttributeAwareUnionTypeNode;
use Rector\AttributeAwarePhpDoc\Contract\AttributeNodeAwareFactory\AttributeAwareNodeFactoryAwareInterface;
use Rector\BetterPhpDocParser\Contract\PhpDocNode\AttributeAwareNodeInterface;
use Rector\Core\Exception\ShouldNotHappenException;
use Rector\AttributeAwarePhpDoc\Contract\AttributeNodeAwareFactory\AttributeNodeAwareFactoryInterface;
use Symplify\SimplePhpDocParser\PhpDocNodeTraverser;
/**
* @see \Rector\Tests\BetterPhpDocParser\Attributes\Ast\AttributeAwareNodeFactoryTest
@ -19,41 +20,65 @@ use Rector\Core\Exception\ShouldNotHappenException;
final class AttributeAwareNodeFactory
{
/**
* @var AttributeAwareNodeFactoryCollector
* @var AttributeNodeAwareFactoryInterface[]
*/
private $attributeAwareNodeFactoryCollector;
private $attributeAwareNodeFactories = [];
public function __construct(AttributeAwareNodeFactoryCollector $attributeAwareNodeFactoryCollector)
/**
* @var PhpDocNodeTraverser
*/
private $phpDocNodeTraverser;
/**
* @param AttributeNodeAwareFactoryInterface[] $attributeAwareNodeFactories
*/
public function __construct(array $attributeAwareNodeFactories, PhpDocNodeTraverser $phpDocNodeTraverser)
{
$this->attributeAwareNodeFactoryCollector = $attributeAwareNodeFactoryCollector;
foreach ($attributeAwareNodeFactories as $attributeAwareNodeFactory) {
// prevents cyclic dependency
if ($attributeAwareNodeFactory instanceof AttributeAwareNodeFactoryAwareInterface) {
$attributeAwareNodeFactory->setAttributeAwareNodeFactory($this);
}
}
$this->attributeAwareNodeFactories = $attributeAwareNodeFactories;
$this->phpDocNodeTraverser = $phpDocNodeTraverser;
}
/**
* @return PhpDocNode|PhpDocChildNode|PhpDocTagValueNode|AttributeAwareNodeInterface
* @template T of \PHPStan\PhpDocParser\Ast\Node
* @param T $node
* @return T
*/
public function createFromNode(Node $node, string $docContent): AttributeAwareNodeInterface
public function createFromNode(Node $node, string $docContent): Node
{
if ($node instanceof AttributeAwareNodeInterface) {
return $node;
}
$node = $this->phpDocNodeTraverser->traverseWithCallable($node, $docContent, function (
Node $node,
string $docContent
): Node {
if ($node instanceof UnionTypeNode && ! $node instanceof AttributeAwareUnionTypeNode) {
return new AttributeAwareUnionTypeNode($node->types, $docContent);
}
foreach ($this->attributeAwareNodeFactoryCollector->provide() as $attributeNodeAwareFactory) {
if (! $attributeNodeAwareFactory->isMatch($node)) {
if ($node instanceof ArrayShapeItemNode && ! $node instanceof AttributeAwareArrayShapeItemNode) {
return new AttributeAwareArrayShapeItemNode(
$node->keyName,
$node->optional,
$node->valueType,
$docContent
);
}
return $node;
});
foreach ($this->attributeAwareNodeFactories as $attributeAwareNodeFactory) {
if (! $attributeAwareNodeFactory->isMatch($node)) {
continue;
}
// prevents cyclic dependency
if ($attributeNodeAwareFactory instanceof AttributeAwareNodeFactoryAwareInterface) {
$attributeNodeAwareFactory->setAttributeAwareNodeFactory($this);
}
return $attributeNodeAwareFactory->create($node, $docContent);
return $attributeAwareNodeFactory->create($node, $docContent);
}
throw new ShouldNotHappenException(sprintf(
'Node "%s" was missed in "%s". Generate it with: bin/rector sync-types',
get_class($node),
__METHOD__
));
return $node;
}
}

View File

@ -5,17 +5,13 @@ declare(strict_types=1);
namespace Rector\BetterPhpDocParser\Attributes\Ast\PhpDoc;
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode;
use Rector\BetterPhpDocParser\Attributes\Attribute\AttributeTrait;
use Rector\BetterPhpDocParser\Contract\PhpDocNode\AttributeAwareNodeInterface;
/**
* Useful for annotation class based annotation, e.g. @ORM\Entity to prevent space
* between the @ORM\Entity and (someContent)
*/
final class SpacelessPhpDocTagNode extends PhpDocTagNode implements AttributeAwareNodeInterface
final class SpacelessPhpDocTagNode extends PhpDocTagNode
{
use AttributeTrait;
public function __toString(): string
{
return $this->name . $this->value;

View File

@ -1,29 +0,0 @@
<?php
declare(strict_types=1);
namespace Rector\BetterPhpDocParser\Attributes\Attribute;
trait AttributeTrait
{
/**
* @var mixed[]
*/
private $attributes = [];
/**
* @return mixed|null
*/
public function getAttribute(string $name)
{
return $this->attributes[$name] ?? null;
}
/**
* @param mixed $value
*/
public function setAttribute(string $name, $value): void
{
$this->attributes[$name] = $value;
}
}

View File

@ -1,14 +0,0 @@
<?php
declare(strict_types=1);
namespace Rector\BetterPhpDocParser\Contract\PhpDocNode;
use PHPStan\PhpDocParser\Ast\Node;
interface AttributeAwareNodeInterface extends Node
{
public function setAttribute(string $name, $value): void;
public function getAttribute(string $name);
}

View File

@ -1,11 +0,0 @@
<?php
declare(strict_types=1);
namespace Rector\BetterPhpDocParser\Contract\PhpDocNode;
use PHPStan\PhpDocParser\Ast\Node;
interface TypeAwareTagValueNodeInterface extends Node
{
}

View File

@ -18,14 +18,12 @@ use PHPStan\PhpDocParser\Ast\PhpDoc\VarTagValueNode;
use PHPStan\Type\MixedType;
use PHPStan\Type\Type;
use Rector\AttributeAwarePhpDoc\Ast\PhpDoc\AttributeAwarePhpDocNode;
use Rector\AttributeAwarePhpDoc\Ast\PhpDoc\AttributeAwarePhpDocTagNode;
use Rector\AttributeAwarePhpDoc\Ast\PhpDoc\AttributeAwareReturnTagValueNode;
use Rector\BetterPhpDocParser\Annotation\AnnotationNaming;
use Rector\BetterPhpDocParser\Attributes\Ast\PhpDoc\SpacelessPhpDocTagNode;
use Rector\BetterPhpDocParser\Contract\PhpDocNode\AttributeAwareNodeInterface;
use Rector\BetterPhpDocParser\Contract\PhpDocNode\ClassNameAwareTagInterface;
use Rector\BetterPhpDocParser\Contract\PhpDocNode\ShortNameAwareTagInterface;
use Rector\BetterPhpDocParser\Contract\PhpDocNode\TypeAwareTagValueNodeInterface;
use Rector\BetterPhpDocParser\ValueObject\NodeTypes;
use Rector\ChangesReporting\Collector\RectorChangeCollector;
use Rector\Core\Configuration\CurrentNodeProvider;
use Rector\Core\Exception\NotImplementedYetException;
@ -176,27 +174,26 @@ final class PhpDocInfo
}
/**
* @return PhpDocTagNode[]|AttributeAwareNodeInterface[]
* @return array<PhpDocTagNode>
*/
public function getTagsByName(string $name): array
{
$name = $this->annotationNaming->normalizeName($name);
/** @var PhpDocTagNode[]|AttributeAwareNodeInterface[] $tags */
$tags = $this->phpDocNode->getTags();
$tags = array_filter($tags, function (PhpDocTagNode $tag) use ($name): bool {
return $tag->name === $name;
});
$tags = array_values($tags);
$tags = array_values($tags);
return array_values($tags);
}
public function getParamType(string $name): Type
{
$attributeAwareParamTagValueNode = $this->getParamTagValueByName($name);
return $this->getTypeOrMixed($attributeAwareParamTagValueNode);
$paramTagValueByName = $this->getParamTagValueByName($name);
return $this->getTypeOrMixed($paramTagValueByName);
}
/**
@ -302,7 +299,7 @@ final class PhpDocInfo
/**
* @template T of \PHPStan\PhpDocParser\Ast\Node
* @param class-string<T> $type
* @return T[]
* @return array<T>
*/
public function findAllByType(string $type): array
{
@ -332,9 +329,14 @@ final class PhpDocInfo
$foundTagsValueNodes[] = $phpDocChildNode->value;
}
/** @var \PHPStan\PhpDocParser\Ast\Node[] $foundTagsValueNodes */
return $foundTagsValueNodes;
}
/**
* @template T of \PHPStan\PhpDocParser\Ast\Node
* @param class-string<T> $type
*/
public function removeByType(string $type): void
{
$this->ensureTypeIsTagValueNode($type, __METHOD__);
@ -390,8 +392,8 @@ final class PhpDocInfo
$name = $this->resolveNameForPhpDocTagValueNode($phpDocTagValueNode);
$attributeAwarePhpDocTagNode = new AttributeAwarePhpDocTagNode($name, $phpDocTagValueNode);
$this->addPhpDocTagNode($attributeAwarePhpDocTagNode);
$phpDocTagNode = new PhpDocTagNode($name, $phpDocTagValueNode);
$this->addPhpDocTagNode($phpDocTagNode);
}
public function isNewNode(): bool
@ -413,9 +415,8 @@ final class PhpDocInfo
return $this->isSingleLine;
}
public function getReturnTagValue(): ?AttributeAwareReturnTagValueNode
public function getReturnTagValue(): ?ReturnTagValueNode
{
/** @var AttributeAwareReturnTagValueNode[] $returnTagValueNodes */
$returnTagValueNodes = $this->phpDocNode->getReturnTagValues();
return $returnTagValueNodes[0] ?? null;
}
@ -481,12 +482,14 @@ final class PhpDocInfo
private function ensureTypeIsTagValueNode(string $type, string $location): void
{
if (StaticInstanceOf::isOneOf($type, [
/** @var array<class-string> $desiredTypes */
$desiredTypes = array_merge([
PhpDocTagValueNode::class,
PhpDocTagNode::class,
TypeAwareTagValueNodeInterface::class,
PhpAttributableTagNodeInterface::class,
])) {
], NodeTypes::TYPE_AWARE_NODES);
if (StaticInstanceOf::isOneOf($type, $desiredTypes)) {
return;
}

View File

@ -14,7 +14,7 @@ use Rector\AttributeAwarePhpDoc\Ast\PhpDoc\AttributeAwarePhpDocNode;
use Rector\BetterPhpDocParser\Annotation\AnnotationNaming;
use Rector\BetterPhpDocParser\Attributes\Ast\AttributeAwareNodeFactory;
use Rector\BetterPhpDocParser\Attributes\Attribute\Attribute;
use Rector\BetterPhpDocParser\Contract\PhpDocNode\AttributeAwareNodeInterface;
use Rector\BetterPhpDocParser\Contract\PhpDocNodeFactoryInterface;
use Rector\BetterPhpDocParser\PhpDocParser\BetterPhpDocParser;
use Rector\BetterPhpDocParser\ValueObject\StartAndEnd;
@ -168,7 +168,6 @@ final class PhpDocInfoFactory
}
$phpDocChildNodes = $attributeAwarePhpDocNode->children;
/** @var AttributeAwareNodeInterface $lastChildNode */
$lastChildNode = array_pop($phpDocChildNodes);
/** @var StartAndEnd $startAndEnd */

View File

@ -5,12 +5,12 @@ declare(strict_types=1);
namespace Rector\BetterPhpDocParser\PhpDocManipulator;
use PhpParser\Node\Param;
use PHPStan\PhpDocParser\Ast\PhpDoc\ReturnTagValueNode;
use PHPStan\PhpDocParser\Ast\PhpDoc\VarTagValueNode;
use PHPStan\Type\Constant\ConstantArrayType;
use PHPStan\Type\MixedType;
use PHPStan\Type\NeverType;
use PHPStan\Type\Type;
use Rector\AttributeAwarePhpDoc\Ast\PhpDoc\AttributeAwareReturnTagValueNode;
use Rector\AttributeAwarePhpDoc\Ast\PhpDoc\AttributeAwareVarTagValueNode;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo;
use Rector\NodeTypeResolver\TypeComparator\TypeComparator;
use Rector\StaticTypeMapper\StaticTypeMapper;
@ -65,8 +65,8 @@ final class PhpDocTypeChanger
$phpDocInfo->markAsChanged();
} else {
// add completely new one
$attributeAwareVarTagValueNode = new AttributeAwareVarTagValueNode($newPHPStanPhpDocType, '', '');
$phpDocInfo->addTagValueNode($attributeAwareVarTagValueNode);
$varTagValueNode = new VarTagValueNode($newPHPStanPhpDocType, '', '');
$phpDocInfo->addTagValueNode($varTagValueNode);
}
}
@ -87,8 +87,8 @@ final class PhpDocTypeChanger
$phpDocInfo->markAsChanged();
} else {
// add completely new one
$attributeAwareReturnTagValueNode = new AttributeAwareReturnTagValueNode($newPHPStanPhpDocType, '');
$phpDocInfo->addTagValueNode($attributeAwareReturnTagValueNode);
$returnTagValueNode = new ReturnTagValueNode($newPHPStanPhpDocType, '');
$phpDocInfo->addTagValueNode($returnTagValueNode);
}
}

View File

@ -6,10 +6,10 @@ namespace Rector\BetterPhpDocParser\PhpDocManipulator;
use PhpParser\Node;
use PhpParser\Node\Stmt\Expression;
use PHPStan\PhpDocParser\Ast\PhpDoc\VarTagValueNode;
use PHPStan\Type\MixedType;
use PHPStan\Type\Type;
use PHPStan\Type\TypeWithClassName;
use Rector\AttributeAwarePhpDoc\Ast\PhpDoc\AttributeAwareVarTagValueNode;
use Rector\AttributeAwarePhpDoc\Ast\Type\FullyQualifiedIdentifierTypeNode;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
@ -47,13 +47,8 @@ final class VarAnnotationManipulator
$fullyQualifiedIdentifierTypeNode = new FullyQualifiedIdentifierTypeNode($typeWithClassName->getClassName());
$attributeAwareVarTagValueNode = new AttributeAwareVarTagValueNode(
$fullyQualifiedIdentifierTypeNode,
'$' . $variableName,
''
);
$phpDocInfo->addTagValueNode($attributeAwareVarTagValueNode);
$varTagValueNode = new VarTagValueNode($fullyQualifiedIdentifierTypeNode, '$' . $variableName, '');
$phpDocInfo->addTagValueNode($varTagValueNode);
}
public function decorateNodeWithType(Node $node, Type $staticType): void

View File

@ -22,7 +22,6 @@ use Rector\BetterPhpDocParser\Contract\PhpDocParserAwareInterface;
use Rector\BetterPhpDocParser\Contract\SpecificPhpDocNodeFactoryInterface;
use Rector\BetterPhpDocParser\Contract\StringTagMatchingPhpDocNodeFactoryInterface;
use Rector\BetterPhpDocParser\PhpDocNodeFactory\MultiPhpDocNodeFactory;
use Rector\BetterPhpDocParser\Printer\MultilineSpaceFormatPreserver;
use Rector\BetterPhpDocParser\ValueObject\StartAndEnd;
use Rector\Core\Configuration\CurrentNodeProvider;
use Rector\Core\Exception\ShouldNotHappenException;
@ -40,12 +39,6 @@ final class BetterPhpDocParser extends PhpDocParser
*/
private const TAG_REGEX = '#@(var|param|return|throws|property|deprecated)#';
/**
* @see https://regex101.com/r/iCJqCv/1
* @var string
*/
private const SPACE_REGEX = '#\s+#';
/**
* @var PhpDocNodeFactoryInterface[]
*/
@ -66,11 +59,6 @@ final class BetterPhpDocParser extends PhpDocParser
*/
private $attributeAwareNodeFactory;
/**
* @var MultilineSpaceFormatPreserver
*/
private $multilineSpaceFormatPreserver;
/**
* @var CurrentNodeProvider
*/
@ -99,7 +87,6 @@ final class BetterPhpDocParser extends PhpDocParser
TypeParser $typeParser,
ConstExprParser $constExprParser,
AttributeAwareNodeFactory $attributeAwareNodeFactory,
MultilineSpaceFormatPreserver $multilineSpaceFormatPreserver,
CurrentNodeProvider $currentNodeProvider,
ClassAnnotationMatcher $classAnnotationMatcher,
AnnotationContentResolver $annotationContentResolver,
@ -108,15 +95,14 @@ final class BetterPhpDocParser extends PhpDocParser
) {
parent::__construct($typeParser, $constExprParser);
$this->setPhpDocNodeFactories($phpDocNodeFactories);
$this->privatesCaller = new PrivatesCaller();
$this->privatesAccessor = new PrivatesAccessor();
$this->attributeAwareNodeFactory = $attributeAwareNodeFactory;
$this->multilineSpaceFormatPreserver = $multilineSpaceFormatPreserver;
$this->currentNodeProvider = $currentNodeProvider;
$this->classAnnotationMatcher = $classAnnotationMatcher;
$this->annotationContentResolver = $annotationContentResolver;
$this->setPhpDocNodeFactories($phpDocNodeFactories);
$this->stringTagMatchingPhpDocNodeFactories = $stringTagMatchingPhpDocNodeFactories;
}
@ -223,6 +209,8 @@ final class BetterPhpDocParser extends PhpDocParser
$docContent = $this->annotationContentResolver->resolveFromTokenIterator($originalTokenIterator);
$tokenStart = $this->getTokenIteratorIndex($tokenIterator);
/** @var PhpDocNode $phpDocNode */
$phpDocNode = $this->privatesCaller->callPrivateMethod($this, 'parseChild', [$tokenIterator]);
$tokenEnd = $this->resolveTokenEnd($tokenIterator);
@ -232,26 +220,6 @@ final class BetterPhpDocParser extends PhpDocParser
$attributeAwareNode = $this->attributeAwareNodeFactory->createFromNode($phpDocNode, $docContent);
$attributeAwareNode->setAttribute(Attribute::START_END, $startAndEnd);
$possibleMultilineText = $this->multilineSpaceFormatPreserver->resolveCurrentPhpDocNodeText(
$attributeAwareNode
);
if ($possibleMultilineText) {
// add original text, for keeping trimmed spaces
$originalContent = $this->getOriginalContentFromTokenIterator($tokenIterator);
// we try to match original content without trimmed spaces
$currentTextPattern = '#(?<line>' . preg_quote($possibleMultilineText, '#') . ')#s';
$currentTextPattern = Strings::replace($currentTextPattern, self::SPACE_REGEX, '\s+');
$match = Strings::match($originalContent, $currentTextPattern);
if (isset($match['line'])) {
$attributeAwareNode->setAttribute(Attribute::ORIGINAL_CONTENT, $match['line']);
}
}
return $attributeAwareNode;
}
@ -328,32 +296,6 @@ final class BetterPhpDocParser extends PhpDocParser
return $this->adjustTokenEndToFitClassAnnotation($tokenIterator, $tokenEnd);
}
private function getOriginalContentFromTokenIterator(TokenIterator $tokenIterator): string
{
$originalTokens = $this->privatesAccessor->getPrivateProperty($tokenIterator, 'tokens');
$originalContent = '';
foreach ($originalTokens as $originalToken) {
// skip opening
if ($originalToken[1] === Lexer::TOKEN_OPEN_PHPDOC) {
continue;
}
// skip closing
if ($originalToken[1] === Lexer::TOKEN_CLOSE_PHPDOC) {
continue;
}
if ($originalToken[1] === Lexer::TOKEN_PHPDOC_EOL) {
$originalToken[0] = PHP_EOL;
}
$originalContent .= $originalToken[0];
}
return trim($originalContent);
}
/**
* @see https://github.com/rectorphp/rector/issues/2158
*

View File

@ -9,10 +9,7 @@ use PHPStan\PhpDocParser\Ast\Node;
use PHPStan\PhpDocParser\Ast\PhpDoc\GenericTagValueNode;
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode;
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTextNode;
use Rector\AttributeAwarePhpDoc\Ast\PhpDoc\AttributeAwareGenericTagValueNode;
use Rector\AttributeAwarePhpDoc\Ast\PhpDoc\AttributeAwarePhpDocTagNode;
use Rector\BetterPhpDocParser\Attributes\Attribute\Attribute;
use Rector\BetterPhpDocParser\Contract\PhpDocNode\AttributeAwareNodeInterface;
final class MultilineSpaceFormatPreserver
{
@ -50,33 +47,29 @@ final class MultilineSpaceFormatPreserver
/**
* Fix multiline BC break - https://github.com/phpstan/phpdoc-parser/pull/26/files
*/
public function fixMultilineDescriptions(AttributeAwareNodeInterface $attributeAwareNode): void
public function fixMultilineDescriptions(Node $node): void
{
$originalContent = $attributeAwareNode->getAttribute(Attribute::ORIGINAL_CONTENT);
$originalContent = $node->getAttribute(Attribute::ORIGINAL_CONTENT);
if (! $originalContent) {
return;
}
$nodeWithRestoredSpaces = $this->restoreOriginalSpacingInText($attributeAwareNode);
if (! $nodeWithRestoredSpaces instanceof AttributeAwareNodeInterface) {
$nodeWithRestoredSpaces = $this->restoreOriginalSpacingInText($node);
if (! $nodeWithRestoredSpaces instanceof Node) {
return;
}
$attributeAwareNode = $nodeWithRestoredSpaces;
$attributeAwareNode->setAttribute(Attribute::HAS_DESCRIPTION_WITH_ORIGINAL_SPACES, true);
$node = $nodeWithRestoredSpaces;
$node->setAttribute(Attribute::HAS_DESCRIPTION_WITH_ORIGINAL_SPACES, true);
}
/**
* @param PhpDocTextNode|AttributeAwareNodeInterface $attributeAwareNode
*/
private function restoreOriginalSpacingInText(
AttributeAwareNodeInterface $attributeAwareNode
): ?AttributeAwareNodeInterface {
private function restoreOriginalSpacingInText(Node $node): ?Node
{
/** @var string $originalContent */
$originalContent = $attributeAwareNode->getAttribute(Attribute::ORIGINAL_CONTENT);
$originalContent = $node->getAttribute(Attribute::ORIGINAL_CONTENT);
$oldSpaces = Strings::matchAll($originalContent, '#\s+#ms');
$currentText = $this->resolveCurrentPhpDocNodeText($attributeAwareNode);
$currentText = $this->resolveCurrentPhpDocNodeText($node);
if ($currentText === null) {
return null;
}
@ -105,33 +98,28 @@ final class MultilineSpaceFormatPreserver
return null;
}
$this->decoratePhpDocNodeWithNewText($attributeAwareNode, $newText);
return $attributeAwareNode;
$this->decoratePhpDocNodeWithNewText($node, $newText);
return $node;
}
private function decoratePhpDocNodeWithNewText(
AttributeAwareNodeInterface $attributeAwareNode,
string $newText
): void {
if ($attributeAwareNode instanceof PhpDocTagNode && property_exists(
$attributeAwareNode->value,
'description'
)) {
$attributeAwareNode->value->description = $newText;
private function decoratePhpDocNodeWithNewText(Node $node, string $newText): void
{
if ($node instanceof PhpDocTagNode && property_exists($node->value, 'description')) {
$node->value->description = $newText;
}
if ($attributeAwareNode instanceof PhpDocTextNode) {
$attributeAwareNode->text = $newText;
if ($node instanceof PhpDocTextNode) {
$node->text = $newText;
}
if (! $attributeAwareNode instanceof AttributeAwarePhpDocTagNode) {
if (! $node instanceof PhpDocTagNode) {
return;
}
if (! $attributeAwareNode->value instanceof AttributeAwareGenericTagValueNode) {
if (! $node->value instanceof GenericTagValueNode) {
return;
}
$attributeAwareNode->value->value = $newText;
$node->value->value = $newText;
}
}

View File

@ -5,6 +5,7 @@ declare(strict_types=1);
namespace Rector\BetterPhpDocParser\Printer;
use Nette\Utils\Strings;
use PHPStan\PhpDocParser\Ast\Node;
use PHPStan\PhpDocParser\Ast\PhpDoc\GenericTagValueNode;
use PHPStan\PhpDocParser\Ast\PhpDoc\ParamTagValueNode;
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode;
@ -15,7 +16,7 @@ use PHPStan\PhpDocParser\Ast\PhpDoc\VarTagValueNode;
use PHPStan\PhpDocParser\Lexer\Lexer;
use Rector\AttributeAwarePhpDoc\Ast\PhpDoc\AttributeAwarePhpDocNode;
use Rector\BetterPhpDocParser\Attributes\Attribute\Attribute;
use Rector\BetterPhpDocParser\Contract\PhpDocNode\AttributeAwareNodeInterface;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo;
use Rector\BetterPhpDocParser\ValueObject\StartAndEnd;
use Rector\Core\Exception\ShouldNotHappenException;
@ -218,7 +219,7 @@ final class PhpDocInfoPrinter
}
private function printNode(
AttributeAwareNodeInterface $attributeAwareNode,
Node $node,
?StartAndEnd $startAndEnd = null,
int $key = 0,
int $nodeCount = 0
@ -226,11 +227,11 @@ final class PhpDocInfoPrinter
$output = '';
/** @var StartAndEnd|null $startAndEnd */
$startAndEnd = $attributeAwareNode->getAttribute(Attribute::START_END) ?: $startAndEnd;
$this->multilineSpaceFormatPreserver->fixMultilineDescriptions($attributeAwareNode);
$startAndEnd = $node->getAttribute(Attribute::START_END) ?: $startAndEnd;
$this->multilineSpaceFormatPreserver->fixMultilineDescriptions($node);
if ($startAndEnd !== null) {
$isLastToken = ($nodeCount === $key);
$isLastToken = $nodeCount === $key;
$output = $this->addTokensFromTo(
$output,
@ -242,26 +243,26 @@ final class PhpDocInfoPrinter
$this->currentTokenPosition = $startAndEnd->getEnd();
}
if ($attributeAwareNode instanceof PhpDocTagNode) {
if ($node instanceof PhpDocTagNode) {
if ($startAndEnd !== null) {
return $this->printPhpDocTagNode($attributeAwareNode, $startAndEnd, $output);
return $this->printPhpDocTagNode($node, $startAndEnd, $output);
}
return $output . self::NEWLINE_ASTERISK . $this->printAttributeWithAsterisk($attributeAwareNode);
return $output . self::NEWLINE_ASTERISK . $this->printAttributeWithAsterisk($node);
}
if (! $attributeAwareNode instanceof PhpDocTextNode && ! $attributeAwareNode instanceof GenericTagValueNode && $startAndEnd) {
$nodeContent = (string) $attributeAwareNode;
if (! $node instanceof PhpDocTextNode && ! $node instanceof GenericTagValueNode && $startAndEnd) {
$nodeContent = (string) $node;
return $this->originalSpacingRestorer->restoreInOutputWithTokensStartAndEndPosition(
$attributeAwareNode,
$node,
$nodeContent,
$this->tokens,
$startAndEnd
);
}
return $output . $this->printAttributeWithAsterisk($attributeAwareNode);
return $output . $this->printAttributeWithAsterisk($node);
}
private function printEnd(string $output): string
@ -269,6 +270,9 @@ final class PhpDocInfoPrinter
$lastTokenPosition = $this->attributeAwarePhpDocNode->getAttribute(
Attribute::LAST_TOKEN_POSITION
) ?: $this->currentTokenPosition;
if ($lastTokenPosition === 0) {
$lastTokenPosition = 1;
}
return $this->addTokensFromTo($output, $lastTokenPosition, $this->tokenCount, true);
}
@ -301,20 +305,13 @@ final class PhpDocInfoPrinter
return $this->appendToOutput($output, $from, $to, $positionJumpSet);
}
/**
* @param PhpDocTagNode|AttributeAwareNodeInterface $phpDocTagNode
*/
private function printPhpDocTagNode(
PhpDocTagNode $phpDocTagNode,
StartAndEnd $startAndEnd,
string $output
): string {
$output .= $phpDocTagNode->name;
$phpDocTagNodeValue = $phpDocTagNode->value;
if (! $phpDocTagNodeValue instanceof AttributeAwareNodeInterface) {
throw new ShouldNotHappenException();
}
$nodeOutput = $this->printNode($phpDocTagNodeValue, $startAndEnd);
$tagSpaceSeparator = $this->resolveTagSpaceSeparator($phpDocTagNode);
@ -341,10 +338,9 @@ final class PhpDocInfoPrinter
return $output . $nodeOutput;
}
private function printAttributeWithAsterisk(AttributeAwareNodeInterface $attributeAwareNode): string
private function printAttributeWithAsterisk(Node $node): string
{
$content = (string) $attributeAwareNode;
$content = (string) $node;
return $this->explodeAndImplode($content, PHP_EOL, self::NEWLINE_ASTERISK);
}
@ -357,24 +353,40 @@ final class PhpDocInfoPrinter
return $this->removedNodePositions;
}
/** @var AttributeAwareNodeInterface[] $removedNodes */
$removedNodes = array_diff(
$this->phpDocInfo->getOriginalPhpDocNode()
->children,
$this->attributeAwarePhpDocNode->children
);
$lastEndPosition = null;
foreach ($removedNodes as $removedNode) {
/** @var StartAndEnd $removedPhpDocNodeInfo */
$removedPhpDocNodeInfo = $removedNode->getAttribute(Attribute::START_END);
// change start position to start of the line, so the whole line is removed
$seekPosition = $removedPhpDocNodeInfo->getStart();
while ($this->tokens[$seekPosition][1] !== Lexer::TOKEN_HORIZONTAL_WS) {
while ($seekPosition >= 0 && $this->tokens[$seekPosition][1] !== Lexer::TOKEN_HORIZONTAL_WS) {
if ($this->tokens[$seekPosition][1] === Lexer::TOKEN_PHPDOC_EOL) {
break;
}
// do not colide
if ($lastEndPosition < $seekPosition) {
break;
}
--$seekPosition;
}
$this->removedNodePositions[] = new StartAndEnd($seekPosition - 1, $removedPhpDocNodeInfo->getEnd());
$lastEndPosition = $removedPhpDocNodeInfo->getEnd();
$this->removedNodePositions[] = new StartAndEnd(max(
0,
$seekPosition - 1
), $removedPhpDocNodeInfo->getEnd());
}
return $this->removedNodePositions;
@ -388,6 +400,7 @@ final class PhpDocInfoPrinter
for ($i = $from; $i < $to; ++$i) {
while (isset($positionJumpSet[$i])) {
$i = $positionJumpSet[$i];
continue;
}
$output .= $this->tokens[$i][0] ?? '';
@ -419,9 +432,6 @@ final class PhpDocInfoPrinter
return '';
}
/**
* @param AttributeAwareNodeInterface&PhpDocTagNode $phpDocTagNode
*/
private function hasDescription(PhpDocTagNode $phpDocTagNode): bool
{
$hasDescriptionWithOriginalSpaces = $phpDocTagNode->getAttribute(

View File

@ -4,8 +4,8 @@ declare(strict_types=1);
namespace Rector\BetterPhpDocParser\Printer;
use PHPStan\PhpDocParser\Ast\PhpDoc\GenericTagValueNode;
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode;
use Rector\AttributeAwarePhpDoc\Ast\PhpDoc\AttributeAwareGenericTagValueNode;
use Rector\AttributeAwarePhpDoc\Ast\PhpDoc\AttributeAwareParamTagValueNode;
final class SpacePatternFactory
@ -24,7 +24,7 @@ final class SpacePatternFactory
return $this->createSpacePatternForParamTagValueNode($phpDocTagNode->value, $spacePattern);
}
if ($phpDocTagNode->value instanceof AttributeAwareGenericTagValueNode) {
if ($phpDocTagNode->value instanceof GenericTagValueNode) {
$originalValue = $phpDocTagNode->value->getAttribute('original_value') ?? $phpDocTagNode->value->value;
// break by line break, to prevent false content positive

View File

@ -8,8 +8,6 @@ use Nette\Utils\Arrays;
use Nette\Utils\Strings;
use PHPStan\PhpDocParser\Ast\Node;
use PHPStan\PhpDocParser\Lexer\Lexer;
use Rector\BetterPhpDocParser\Contract\Doctrine\DoctrineTagNodeInterface;
use Rector\BetterPhpDocParser\Contract\PhpDocNode\ShortNameAwareTagInterface;
use Rector\BetterPhpDocParser\ValueObject\StartAndEnd;
final class WhitespaceDetector
@ -29,11 +27,6 @@ final class WhitespaceDetector
$oldWhitespaces = [];
$start = $startAndEnd->getStart();
// this is needed, because of 1 token taken from tokens and added annotation name: "ORM" + "\X" → "ORM\X"
// todo, this might be needed to be dynamic, based on taken tokens count (some Collector?)
if ($node instanceof DoctrineTagNodeInterface) {
--$start;
}
for ($i = $start; $i < $startAndEnd->getEnd(); ++$i) {
/** @var string $tokenValue */
@ -42,11 +35,7 @@ final class WhitespaceDetector
if ($tokens[$i][1] === Lexer::TOKEN_HORIZONTAL_WS) {
// give back "\s+\*" as well
// do not overlap to previous node
if (($node instanceof DoctrineTagNodeInterface || $node instanceof ShortNameAwareTagInterface) &&
$i - 1 > $start &&
isset($tokens[$i - 1]) &&
$tokens[$i - 1][1] === Lexer::TOKEN_PHPDOC_EOL
) {
if ($i - 1 > $start && isset($tokens[$i - 1]) && $tokens[$i - 1][1] === Lexer::TOKEN_PHPDOC_EOL) {
$previousTokenValue = $tokens[$i - 1][0];
if (Strings::match($previousTokenValue, self::SPACE_BEFORE_ASTERISK_REGEX)) {
$tokenValue = $previousTokenValue . $tokenValue;
@ -57,6 +46,14 @@ final class WhitespaceDetector
continue;
}
// fixes phpdoc parser multiline spaces BC break https://github.com/phpstan/phpdoc-parser/commit/b451b2f27a97c8c288de63db79c2a843727d4326
if ($tokens[$i][1] === Lexer::TOKEN_PHPDOC_EOL) {
$nextToken = $tokens[$i + 1];
if ($nextToken[1] !== Lexer::TOKEN_HORIZONTAL_WS) {
$oldWhitespaces[] = $tokens[$i][0];
}
}
// quoted string with spaces?
if ($this->isQuotedStringWithSpaces($tokens, $i)) {
$matches = Strings::matchAll($tokenValue, '#\s+#m');

View File

@ -0,0 +1,36 @@
<?php
declare(strict_types=1);
namespace Rector\BetterPhpDocParser\ValueObject;
use PHPStan\PhpDocParser\Ast\PhpDoc\ParamTagValueNode;
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagValueNode;
use PHPStan\PhpDocParser\Ast\PhpDoc\PropertyTagValueNode;
use PHPStan\PhpDocParser\Ast\PhpDoc\ReturnTagValueNode;
use PHPStan\PhpDocParser\Ast\PhpDoc\ThrowsTagValueNode;
use PHPStan\PhpDocParser\Ast\PhpDoc\VarTagValueNode;
use Rector\BetterPhpDocParser\ValueObject\PhpDocNode\Doctrine\Property_\OneToManyTagValueNode;
use Rector\BetterPhpDocParser\ValueObject\PhpDocNode\JMS\SerializerTypeTagValueNode;
use Rector\BetterPhpDocParser\ValueObject\PhpDocNode\Symfony\Validator\Constraints\AssertChoiceTagValueNode;
use Rector\BetterPhpDocParser\ValueObject\PhpDocNode\Symfony\Validator\Constraints\AssertEmailTagValueNode;
use Rector\BetterPhpDocParser\ValueObject\PhpDocNode\Symfony\Validator\Constraints\AssertRangeTagValueNode;
final class NodeTypes
{
/**
* @var array<class-string<PhpDocTagValueNode>>
*/
public const TYPE_AWARE_NODES = [
VarTagValueNode::class,
ParamTagValueNode::class,
ReturnTagValueNode::class,
ThrowsTagValueNode::class,
PropertyTagValueNode::class,
SerializerTypeTagValueNode::class,
OneToManyTagValueNode::class,
AssertChoiceTagValueNode::class,
AssertEmailTagValueNode::class,
AssertRangeTagValueNode::class,
];
}

View File

@ -5,9 +5,9 @@ declare(strict_types=1);
namespace Rector\BetterPhpDocParser\ValueObject\PhpDocNode;
use Nette\Utils\Strings;
use PHPStan\PhpDocParser\Ast\NodeAttributes;
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagValueNode;
use Rector\BetterPhpDocParser\Attributes\Attribute\AttributeTrait;
use Rector\BetterPhpDocParser\Contract\PhpDocNode\AttributeAwareNodeInterface;
use Rector\BetterPhpDocParser\Contract\PhpDocNode\TagAwareNodeInterface;
use Rector\BetterPhpDocParser\Printer\ArrayPartPhpDocTagPrinter;
use Rector\BetterPhpDocParser\Printer\TagValueNodePrinter;
@ -17,9 +17,9 @@ use Rector\BetterPhpDocParser\ValueObjectFactory\TagValueNodeConfigurationFactor
use Rector\Core\Exception\ShouldNotHappenException;
use Symplify\PackageBuilder\Php\TypeChecker;
abstract class AbstractTagValueNode implements AttributeAwareNodeInterface, PhpDocTagValueNode
abstract class AbstractTagValueNode implements PhpDocTagValueNode
{
use AttributeTrait;
use NodeAttributes;
/**
* @var mixed[]

View File

@ -4,18 +4,14 @@ declare(strict_types=1);
namespace Rector\BetterPhpDocParser\ValueObject\PhpDocNode;
use PHPStan\PhpDocParser\Ast\PhpDoc\GenericTagValueNode;
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode;
use Rector\AttributeAwarePhpDoc\Ast\PhpDoc\AttributeAwareGenericTagValueNode;
use Rector\BetterPhpDocParser\Attributes\Attribute\AttributeTrait;
use Rector\BetterPhpDocParser\Contract\PhpDocNode\AttributeAwareNodeInterface;
/**
* @see \Rector\BetterPhpDocParser\PhpDocNodeFactory\StringMatchingPhpDocNodeFactory\ApiPhpDocNodeFactory
*/
final class ApiPhpDocTagNode extends PhpDocTagNode implements AttributeAwareNodeInterface
final class ApiPhpDocTagNode extends PhpDocTagNode
{
use AttributeTrait;
/**
* @var string
*/
@ -23,7 +19,7 @@ final class ApiPhpDocTagNode extends PhpDocTagNode implements AttributeAwareNode
public function __construct()
{
parent::__construct(self::NAME, new AttributeAwareGenericTagValueNode(''));
parent::__construct(self::NAME, new GenericTagValueNode(''));
}
public function __toString(): string

View File

@ -6,12 +6,11 @@ namespace Rector\BetterPhpDocParser\ValueObject\PhpDocNode\Doctrine\Property_;
use Rector\BetterPhpDocParser\Contract\Doctrine\MappedByNodeInterface;
use Rector\BetterPhpDocParser\Contract\Doctrine\ToManyTagNodeInterface;
use Rector\BetterPhpDocParser\Contract\PhpDocNode\TypeAwareTagValueNodeInterface;
use Rector\BetterPhpDocParser\Printer\ArrayPartPhpDocTagPrinter;
use Rector\BetterPhpDocParser\Printer\TagValueNodePrinter;
use Rector\BetterPhpDocParser\ValueObject\PhpDocNode\Doctrine\AbstractDoctrineTagValueNode;
final class OneToManyTagValueNode extends AbstractDoctrineTagValueNode implements ToManyTagNodeInterface, MappedByNodeInterface, TypeAwareTagValueNodeInterface
final class OneToManyTagValueNode extends AbstractDoctrineTagValueNode implements ToManyTagNodeInterface, MappedByNodeInterface
{
/**
* @var string|null

View File

@ -7,10 +7,9 @@ namespace Rector\BetterPhpDocParser\ValueObject\PhpDocNode\JMS;
use Nette\Utils\Strings;
use Rector\BetterPhpDocParser\Contract\PhpDocNode\ShortNameAwareTagInterface;
use Rector\BetterPhpDocParser\Contract\PhpDocNode\SilentKeyNodeInterface;
use Rector\BetterPhpDocParser\Contract\PhpDocNode\TypeAwareTagValueNodeInterface;
use Rector\BetterPhpDocParser\ValueObject\PhpDocNode\AbstractTagValueNode;
final class SerializerTypeTagValueNode extends AbstractTagValueNode implements TypeAwareTagValueNodeInterface, ShortNameAwareTagInterface, SilentKeyNodeInterface
final class SerializerTypeTagValueNode extends AbstractTagValueNode implements ShortNameAwareTagInterface, SilentKeyNodeInterface
{
/**
* @var string

View File

@ -4,16 +4,13 @@ declare(strict_types=1);
namespace Rector\BetterPhpDocParser\ValueObject\PhpDocNode\Nette;
use PHPStan\PhpDocParser\Ast\PhpDoc\GenericTagValueNode;
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode;
use Rector\AttributeAwarePhpDoc\Ast\PhpDoc\AttributeAwareGenericTagValueNode;
use Rector\BetterPhpDocParser\Attributes\Attribute\AttributeTrait;
use Rector\BetterPhpDocParser\Contract\PhpDocNode\AttributeAwareNodeInterface;
use Rector\PhpAttribute\Contract\PhpAttributableTagNodeInterface;
final class NetteCrossOriginTagNode extends PhpDocTagNode implements PhpAttributableTagNodeInterface, AttributeAwareNodeInterface
final class NetteCrossOriginTagNode extends PhpDocTagNode implements PhpAttributableTagNodeInterface
{
use AttributeTrait;
/**
* @var string
*/
@ -21,7 +18,7 @@ final class NetteCrossOriginTagNode extends PhpDocTagNode implements PhpAttribut
public function __construct()
{
parent::__construct(self::NAME, new AttributeAwareGenericTagValueNode(''));
parent::__construct(self::NAME, new GenericTagValueNode(''));
}
public function getShortName(): string

View File

@ -4,19 +4,16 @@ declare(strict_types=1);
namespace Rector\BetterPhpDocParser\ValueObject\PhpDocNode\Nette;
use PHPStan\PhpDocParser\Ast\PhpDoc\GenericTagValueNode;
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode;
use Rector\AttributeAwarePhpDoc\Ast\PhpDoc\AttributeAwareGenericTagValueNode;
use Rector\BetterPhpDocParser\Attributes\Attribute\AttributeTrait;
use Rector\BetterPhpDocParser\Contract\PhpDocNode\AttributeAwareNodeInterface;
use Rector\PhpAttribute\Contract\PhpAttributableTagNodeInterface;
/**
* @see \Rector\BetterPhpDocParser\PhpDocNodeFactory\StringMatchingPhpDocNodeFactory\NetteInjectPhpDocNodeFactory
*/
final class NetteInjectTagNode extends PhpDocTagNode implements PhpAttributableTagNodeInterface, AttributeAwareNodeInterface
final class NetteInjectTagNode extends PhpDocTagNode implements PhpAttributableTagNodeInterface
{
use AttributeTrait;
/**
* @var string
*/
@ -24,7 +21,7 @@ final class NetteInjectTagNode extends PhpDocTagNode implements PhpAttributableT
public function __construct()
{
parent::__construct(self::NAME, new AttributeAwareGenericTagValueNode(''));
parent::__construct(self::NAME, new GenericTagValueNode(''));
}
public function getShortName(): string

View File

@ -4,19 +4,16 @@ declare(strict_types=1);
namespace Rector\BetterPhpDocParser\ValueObject\PhpDocNode\Nette;
use PHPStan\PhpDocParser\Ast\PhpDoc\GenericTagValueNode;
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode;
use Rector\AttributeAwarePhpDoc\Ast\PhpDoc\AttributeAwareGenericTagValueNode;
use Rector\BetterPhpDocParser\Attributes\Attribute\AttributeTrait;
use Rector\BetterPhpDocParser\Contract\PhpDocNode\AttributeAwareNodeInterface;
use Rector\PhpAttribute\Contract\PhpAttributableTagNodeInterface;
/**
* @see \Rector\BetterPhpDocParser\PhpDocNodeFactory\StringMatchingPhpDocNodeFactory\NettePersistentPhpDocNodeFactory
*/
final class NettePersistentTagNode extends PhpDocTagNode implements PhpAttributableTagNodeInterface, AttributeAwareNodeInterface
final class NettePersistentTagNode extends PhpDocTagNode implements PhpAttributableTagNodeInterface
{
use AttributeTrait;
/**
* @var string
*/
@ -24,7 +21,7 @@ final class NettePersistentTagNode extends PhpDocTagNode implements PhpAttributa
public function __construct()
{
parent::__construct(self::NAME, new AttributeAwareGenericTagValueNode(''));
parent::__construct(self::NAME, new GenericTagValueNode(''));
}
public function getShortName(): string

View File

@ -4,13 +4,12 @@ declare(strict_types=1);
namespace Rector\BetterPhpDocParser\ValueObject\PhpDocNode\PHPUnit;
use PHPStan\PhpDocParser\Ast\NodeAttributes;
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagValueNode;
use Rector\BetterPhpDocParser\Attributes\Attribute\AttributeTrait;
use Rector\BetterPhpDocParser\Contract\PhpDocNode\AttributeAwareNodeInterface;
final class PHPUnitDataProviderTagValueNode implements PhpDocTagValueNode, AttributeAwareNodeInterface
final class PHPUnitDataProviderTagValueNode implements PhpDocTagValueNode
{
use AttributeTrait;
use NodeAttributes;
/**
* @var string

View File

@ -4,18 +4,14 @@ declare(strict_types=1);
namespace Rector\BetterPhpDocParser\ValueObject\PhpDocNode\PHPUnit;
use PHPStan\PhpDocParser\Ast\PhpDoc\GenericTagValueNode;
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode;
use Rector\AttributeAwarePhpDoc\Ast\PhpDoc\AttributeAwareGenericTagValueNode;
use Rector\BetterPhpDocParser\Attributes\Attribute\AttributeTrait;
use Rector\BetterPhpDocParser\Contract\PhpDocNode\AttributeAwareNodeInterface;
/**
* @see \Rector\BetterPhpDocParser\PhpDocNodeFactory\StringMatchingPhpDocNodeFactory\PHPUnitDataDoesNotPerformAssertionDocNodeFactory
*/
final class PHPUnitDoesNotPerformAssertionTagNode extends PhpDocTagNode implements AttributeAwareNodeInterface
final class PHPUnitDoesNotPerformAssertionTagNode extends PhpDocTagNode
{
use AttributeTrait;
/**
* @var string
*/
@ -23,6 +19,6 @@ final class PHPUnitDoesNotPerformAssertionTagNode extends PhpDocTagNode implemen
public function __construct()
{
parent::__construct(self::NAME, new AttributeAwareGenericTagValueNode(''));
parent::__construct(self::NAME, new GenericTagValueNode(''));
}
}

View File

@ -4,17 +4,16 @@ declare(strict_types=1);
namespace Rector\BetterPhpDocParser\ValueObject\PhpDocNode\PHPUnit;
use PHPStan\PhpDocParser\Ast\NodeAttributes;
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagValueNode;
use PHPStan\PhpDocParser\Ast\Type\TypeNode;
use Rector\BetterPhpDocParser\Attributes\Attribute\AttributeTrait;
use Rector\BetterPhpDocParser\Contract\PhpDocNode\AttributeAwareNodeInterface;
/**
* @see \Rector\BetterPhpDocParser\PhpDocNodeFactory\StringMatchingPhpDocNodeFactory\PHPUnitExpectedExceptionDocNodeFactory
*/
final class PHPUnitExpectedExceptionTagValueNode implements PhpDocTagValueNode, AttributeAwareNodeInterface
final class PHPUnitExpectedExceptionTagValueNode implements PhpDocTagValueNode
{
use AttributeTrait;
use NodeAttributes;
/**
* @var string

View File

@ -6,13 +6,12 @@ namespace Rector\BetterPhpDocParser\ValueObject\PhpDocNode\Symfony\Validator\Con
use Rector\BetterPhpDocParser\Contract\PhpDocNode\ShortNameAwareTagInterface;
use Rector\BetterPhpDocParser\Contract\PhpDocNode\SilentKeyNodeInterface;
use Rector\BetterPhpDocParser\Contract\PhpDocNode\TypeAwareTagValueNodeInterface;
use Rector\BetterPhpDocParser\ValueObject\PhpDocNode\AbstractTagValueNode;
/**
* @see \Rector\Tests\BetterPhpDocParser\PhpDocParser\TagValueNodeReprint\TagValueNodeReprintTest
*/
final class AssertChoiceTagValueNode extends AbstractTagValueNode implements TypeAwareTagValueNodeInterface, ShortNameAwareTagInterface, SilentKeyNodeInterface
final class AssertChoiceTagValueNode extends AbstractTagValueNode implements ShortNameAwareTagInterface, SilentKeyNodeInterface
{
public function isCallbackClass(string $class): bool
{

View File

@ -6,14 +6,13 @@ namespace Rector\BetterPhpDocParser\ValueObject\PhpDocNode\Symfony\Validator\Con
use Rector\BetterPhpDocParser\Contract\PhpDocNode\ShortNameAwareTagInterface;
use Rector\BetterPhpDocParser\Contract\PhpDocNode\SilentKeyNodeInterface;
use Rector\BetterPhpDocParser\Contract\PhpDocNode\TypeAwareTagValueNodeInterface;
use Rector\BetterPhpDocParser\ValueObject\PhpDocNode\AbstractTagValueNode;
use Rector\PhpAttribute\Contract\PhpAttributableTagNodeInterface;
/**
* @see \Rector\Tests\BetterPhpDocParser\PhpDocParser\TagValueNodeReprint\TagValueNodeReprintTest
*/
final class AssertEmailTagValueNode extends AbstractTagValueNode implements TypeAwareTagValueNodeInterface, ShortNameAwareTagInterface, PhpAttributableTagNodeInterface, SilentKeyNodeInterface
final class AssertEmailTagValueNode extends AbstractTagValueNode implements ShortNameAwareTagInterface, PhpAttributableTagNodeInterface, SilentKeyNodeInterface
{
public function getShortName(): string
{

View File

@ -5,11 +5,10 @@ declare(strict_types=1);
namespace Rector\BetterPhpDocParser\ValueObject\PhpDocNode\Symfony\Validator\Constraints;
use Rector\BetterPhpDocParser\Contract\PhpDocNode\ShortNameAwareTagInterface;
use Rector\BetterPhpDocParser\Contract\PhpDocNode\TypeAwareTagValueNodeInterface;
use Rector\BetterPhpDocParser\ValueObject\PhpDocNode\AbstractTagValueNode;
use Rector\PhpAttribute\Contract\PhpAttributableTagNodeInterface;
final class AssertRangeTagValueNode extends AbstractTagValueNode implements TypeAwareTagValueNodeInterface, ShortNameAwareTagInterface, PhpAttributableTagNodeInterface
final class AssertRangeTagValueNode extends AbstractTagValueNode implements ShortNameAwareTagInterface, PhpAttributableTagNodeInterface
{
public function getShortName(): string
{

View File

@ -7,6 +7,8 @@ namespace Rector\PHPStanStaticTypeMapper\TypeMapper;
use PhpParser\Node;
use PhpParser\Node\Name;
use PHPStan\PhpDocParser\Ast\Type\ArrayTypeNode;
use PHPStan\PhpDocParser\Ast\Type\GenericTypeNode;
use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode;
use PHPStan\PhpDocParser\Ast\Type\TypeNode;
use PHPStan\Reflection\ReflectionProvider;
use PHPStan\Type\ArrayType;
@ -20,10 +22,7 @@ use PHPStan\Type\ObjectType;
use PHPStan\Type\Type;
use PHPStan\Type\UnionType;
use Rector\AttributeAwarePhpDoc\Ast\Type\AttributeAwareArrayTypeNode;
use Rector\AttributeAwarePhpDoc\Ast\Type\AttributeAwareGenericTypeNode;
use Rector\AttributeAwarePhpDoc\Ast\Type\AttributeAwareIdentifierTypeNode;
use Rector\AttributeAwarePhpDoc\Ast\Type\AttributeAwareUnionTypeNode;
use Rector\BetterPhpDocParser\Contract\PhpDocNode\AttributeAwareNodeInterface;
use Rector\PHPStanStaticTypeMapper\Contract\TypeMapperInterface;
use Rector\PHPStanStaticTypeMapper\PHPStanStaticTypeMapper;
use Rector\PHPStanStaticTypeMapper\TypeAnalyzer\UnionTypeCommonTypeNarrower;
@ -189,10 +188,10 @@ final class ArrayTypeMapper implements TypeMapperInterface
return false;
}
private function createGenericArrayType(ArrayType $arrayType, bool $withKey = false): AttributeAwareGenericTypeNode
private function createGenericArrayType(ArrayType $arrayType, bool $withKey = false): GenericTypeNode
{
$itemTypeNode = $this->phpStanStaticTypeMapper->mapToPHPStanPhpDocTypeNode($arrayType->getItemType());
$attributeAwareIdentifierTypeNode = new AttributeAwareIdentifierTypeNode('array');
$identifierTypeNode = new IdentifierTypeNode('array');
// is class-string[] list only
if ($this->isClassStringArrayType($arrayType)) {
@ -209,13 +208,12 @@ final class ArrayTypeMapper implements TypeMapperInterface
// @see https://github.com/phpstan/phpdoc-parser/blob/98a088b17966bdf6ee25c8a4b634df313d8aa531/tests/PHPStan/Parser/PhpDocParserTest.php#L2692-L2696
foreach ($genericTypes as $genericType) {
/** @var AttributeAwareNodeInterface $genericType */
/** @var \PHPStan\PhpDocParser\Ast\Node $genericType */
$genericType->setAttribute(self::HAS_GENERIC_TYPE_PARENT, $withKey);
}
$attributeAwareIdentifierTypeNode->setAttribute(self::HAS_GENERIC_TYPE_PARENT, $withKey);
return new AttributeAwareGenericTypeNode($attributeAwareIdentifierTypeNode, $genericTypes);
$identifierTypeNode->setAttribute(self::HAS_GENERIC_TYPE_PARENT, $withKey);
return new GenericTypeNode($identifierTypeNode, $genericTypes);
}
private function mapArrayUnionTypeToDocString(ArrayType $arrayType, UnionType $unionType): string
@ -264,15 +262,15 @@ final class ArrayTypeMapper implements TypeMapperInterface
private function createTypeNodeFromGenericClassStringType(
GenericClassStringType $genericClassStringType
): AttributeAwareNodeInterface {
): TypeNode {
$genericType = $genericClassStringType->getGenericType();
if ($genericType instanceof ObjectType && ! $this->reflectionProvider->hasClass($genericType->getClassName())) {
return new AttributeAwareIdentifierTypeNode($genericType->getClassName());
return new IdentifierTypeNode($genericType->getClassName());
}
$itemTypeNode = $this->phpStanStaticTypeMapper->mapToPHPStanPhpDocTypeNode($genericClassStringType);
return new AttributeAwareGenericTypeNode(new AttributeAwareIdentifierTypeNode('array'), [$itemTypeNode]);
return new GenericTypeNode(new IdentifierTypeNode('array'), [$itemTypeNode]);
}
private function isClassStringArrayType(ArrayType $arrayType): bool

View File

@ -6,10 +6,10 @@ namespace Rector\PHPStanStaticTypeMapper\TypeMapper;
use PhpParser\Node;
use PhpParser\Node\Name;
use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode;
use PHPStan\PhpDocParser\Ast\Type\TypeNode;
use PHPStan\Type\BooleanType;
use PHPStan\Type\Type;
use Rector\AttributeAwarePhpDoc\Ast\Type\AttributeAwareIdentifierTypeNode;
use Rector\Core\Php\PhpVersionProvider;
use Rector\Core\ValueObject\PhpVersionFeature;
use Rector\PHPStanStaticTypeMapper\Contract\TypeMapperInterface;
@ -41,10 +41,10 @@ final class BooleanTypeMapper implements TypeMapperInterface
public function mapToPHPStanPhpDocTypeNode(Type $type): TypeNode
{
if ($this->isFalseBooleanTypeWithUnion($type)) {
return new AttributeAwareIdentifierTypeNode('false');
return new IdentifierTypeNode('false');
}
return new AttributeAwareIdentifierTypeNode('bool');
return new IdentifierTypeNode('bool');
}
/**

View File

@ -6,14 +6,14 @@ namespace Rector\PHPStanStaticTypeMapper\TypeMapper;
use PhpParser\Node;
use PhpParser\Node\Expr;
use PHPStan\PhpDocParser\Ast\Type\GenericTypeNode;
use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode;
use PHPStan\PhpDocParser\Ast\Type\TypeNode;
use PHPStan\Type\ClassStringType;
use PHPStan\Type\Generic\GenericClassStringType;
use PHPStan\Type\ObjectType;
use PHPStan\Type\Type;
use PHPStan\Type\VerbosityLevel;
use Rector\AttributeAwarePhpDoc\Ast\Type\AttributeAwareGenericTypeNode;
use Rector\AttributeAwarePhpDoc\Ast\Type\AttributeAwareIdentifierTypeNode;
use Rector\PHPStanStaticTypeMapper\Contract\PHPStanStaticTypeMapperAwareInterface;
use Rector\PHPStanStaticTypeMapper\Contract\TypeMapperInterface;
use Rector\PHPStanStaticTypeMapper\PHPStanStaticTypeMapper;
@ -38,7 +38,7 @@ final class ClassStringTypeMapper implements TypeMapperInterface, PHPStanStaticT
*/
public function mapToPHPStanPhpDocTypeNode(Type $type): TypeNode
{
$attributeAwareIdentifierTypeNode = new AttributeAwareIdentifierTypeNode('class-string');
$attributeAwareIdentifierTypeNode = new IdentifierTypeNode('class-string');
if ($type instanceof GenericClassStringType) {
$genericType = $type->getGenericType();
@ -49,7 +49,7 @@ final class ClassStringTypeMapper implements TypeMapperInterface, PHPStanStaticT
}
$genericTypeNode = $this->phpStanStaticTypeMapper->mapToPHPStanPhpDocTypeNode($genericType);
return new AttributeAwareGenericTypeNode($attributeAwareIdentifierTypeNode, [$genericTypeNode]);
return new GenericTypeNode($attributeAwareIdentifierTypeNode, [$genericTypeNode]);
}
return $attributeAwareIdentifierTypeNode;

Some files were not shown because too many files have changed in this diff Show More