Skip to content

Commit

Permalink
[PHP 8.0] Refactor attributes from magic interface to explicit list (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba authored Mar 20, 2021
1 parent 44375f6 commit 6802663
Show file tree
Hide file tree
Showing 33 changed files with 213 additions and 616 deletions.
2 changes: 0 additions & 2 deletions packages/BetterPhpDocParser/PhpDocInfo/PhpDocInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
use Rector\Core\Exception\NotImplementedYetException;
use Rector\Core\Exception\ShouldNotHappenException;
use Rector\Core\Util\StaticInstanceOf;
use Rector\PhpAttribute\Contract\PhpAttributableTagNodeInterface;
use Rector\StaticTypeMapper\StaticTypeMapper;

/**
Expand Down Expand Up @@ -493,7 +492,6 @@ private function ensureTypeIsTagValueNode(string $type, string $location): void
$desiredTypes = array_merge([
PhpDocTagValueNode::class,
PhpDocTagNode::class,
PhpAttributableTagNodeInterface::class,
], NodeTypes::TYPE_AWARE_NODES);

if (StaticInstanceOf::isOneOf($type, $desiredTypes)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@
use PHPStan\PhpDocParser\Ast\PhpDoc\GenericTagValueNode;
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode;

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
final class SymfonyRequiredTagNode extends PhpDocTagNode
{
/**
* @var string
Expand All @@ -34,17 +32,4 @@ public function getShortName(): string
{
return self::NAME;
}

public function getAttributeClassName(): string
{
return 'Symfony\Contracts\Service\Attribute\Required';
}

/**
* @return mixed[]
*/
public function getAttributableItems(): array
{
return [];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ public function getItems(): array
return $this->items;
}

/**
* @return mixed[]
*/
public function getItemsWithoutDefaults(): array
{
return $this->filterOutMissingItems($this->items);
}

/**
* @param mixed $value
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,4 @@

abstract class AbstractDoctrineTagValueNode extends AbstractTagValueNode implements DoctrineTagNodeInterface, ShortNameAwareTagInterface
{
/**
* @return mixed[]
*/
public function getAttributableItems(): array
{
return $this->filterOutMissingItems($this->items);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@
namespace Rector\BetterPhpDocParser\ValueObject\PhpDocNode\Doctrine\Class_;

use Rector\BetterPhpDocParser\ValueObject\PhpDocNode\Doctrine\AbstractDoctrineTagValueNode;
use Rector\PhpAttribute\Contract\PhpAttributableTagNodeInterface;
use Rector\PhpAttribute\Printer\PhpAttributeGroupFactory;

final class EntityTagValueNode extends AbstractDoctrineTagValueNode implements PhpAttributableTagNodeInterface
final class EntityTagValueNode extends AbstractDoctrineTagValueNode
{
/**
* @var string
Expand All @@ -34,17 +32,4 @@ public function getShortName(): string
{
return '@ORM\Entity';
}

/**
* @return mixed[]
*/
public function getAttributableItems(): array
{
return $this->filterOutMissingItems($this->items);
}

public function getAttributeClassName(): string
{
return PhpAttributeGroupFactory::TO_BE_ANNOUNCED;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@
namespace Rector\BetterPhpDocParser\ValueObject\PhpDocNode\Doctrine\Property_;

use Rector\BetterPhpDocParser\ValueObject\PhpDocNode\Doctrine\AbstractDoctrineTagValueNode;
use Rector\PhpAttribute\Contract\PhpAttributableTagNodeInterface;
use Rector\PhpAttribute\Printer\PhpAttributeGroupFactory;

final class ColumnTagValueNode extends AbstractDoctrineTagValueNode implements PhpAttributableTagNodeInterface
final class ColumnTagValueNode extends AbstractDoctrineTagValueNode
{
public function changeType(string $type): void
{
Expand Down Expand Up @@ -37,9 +35,4 @@ public function getOptions(): array
{
return $this->items['options'] ?? [];
}

public function getAttributeClassName(): string
{
return PhpAttributeGroupFactory::TO_BE_ANNOUNCED;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@

use Rector\BetterPhpDocParser\Contract\PhpDocNode\SilentKeyNodeInterface;
use Rector\BetterPhpDocParser\ValueObject\PhpDocNode\Doctrine\AbstractDoctrineTagValueNode;
use Rector\PhpAttribute\Contract\PhpAttributableTagNodeInterface;
use Rector\PhpAttribute\Printer\PhpAttributeGroupFactory;

/**
* @see \Rector\Tests\BetterPhpDocParser\PhpDocParser\TagValueNodeReprint\TagValueNodeReprintTest
*/
final class GeneratedValueTagValueNode extends AbstractDoctrineTagValueNode implements PhpAttributableTagNodeInterface, SilentKeyNodeInterface
final class GeneratedValueTagValueNode extends AbstractDoctrineTagValueNode implements SilentKeyNodeInterface
{
public function getShortName(): string
{
Expand All @@ -23,9 +21,4 @@ public function getSilentKey(): string
{
return 'strategy';
}

public function getAttributeClassName(): string
{
return PhpAttributeGroupFactory::TO_BE_ANNOUNCED;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,11 @@
namespace Rector\BetterPhpDocParser\ValueObject\PhpDocNode\Doctrine\Property_;

use Rector\BetterPhpDocParser\ValueObject\PhpDocNode\Doctrine\AbstractDoctrineTagValueNode;
use Rector\PhpAttribute\Contract\PhpAttributableTagNodeInterface;
use Rector\PhpAttribute\Printer\PhpAttributeGroupFactory;

final class IdTagValueNode extends AbstractDoctrineTagValueNode implements PhpAttributableTagNodeInterface
final class IdTagValueNode extends AbstractDoctrineTagValueNode
{
public function getShortName(): string
{
return '@ORM\Id';
}

public function getAttributeClassName(): string
{
return PhpAttributeGroupFactory::TO_BE_ANNOUNCED;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@
use Rector\BetterPhpDocParser\Printer\ArrayPartPhpDocTagPrinter;
use Rector\BetterPhpDocParser\Printer\TagValueNodePrinter;
use Rector\BetterPhpDocParser\ValueObject\PhpDocNode\Doctrine\AbstractDoctrineTagValueNode;
use Rector\PhpAttribute\Contract\PhpAttributableTagNodeInterface;
use Rector\PhpAttribute\Printer\PhpAttributeGroupFactory;

final class JoinColumnTagValueNode extends AbstractDoctrineTagValueNode implements TagAwareNodeInterface, PhpAttributableTagNodeInterface
final class JoinColumnTagValueNode extends AbstractDoctrineTagValueNode implements TagAwareNodeInterface
{
/**
* @var string
Expand Down Expand Up @@ -64,9 +62,4 @@ public function changeShortName(string $shortName): void
{
$this->shortName = $shortName;
}

public function getAttributeClassName(): string
{
return PhpAttributeGroupFactory::TO_BE_ANNOUNCED;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,8 @@
use Rector\BetterPhpDocParser\ValueObject\AroundSpaces;
use Rector\BetterPhpDocParser\ValueObject\PhpDocNode\Doctrine\AbstractDoctrineTagValueNode;
use Rector\Core\Exception\ShouldNotHappenException;
use Rector\PhpAttribute\Contract\ManyPhpAttributableTagNodeInterface;
use Rector\PhpAttribute\Contract\PhpAttributableTagNodeInterface;
use Rector\PhpAttribute\Printer\PhpAttributeGroupFactory;

final class JoinTableTagValueNode extends AbstractDoctrineTagValueNode implements PhpAttributableTagNodeInterface, ManyPhpAttributableTagNodeInterface
final class JoinTableTagValueNode extends AbstractDoctrineTagValueNode
{
/**
* @var string
Expand Down Expand Up @@ -96,47 +93,6 @@ public function getShortName(): string
return '@ORM\JoinTable';
}

/**
* @return mixed[]
*/
public function getAttributableItems(): array
{
$items = [];

if ($this->name !== null) {
$items['name'] = $this->name;
}

if ($this->schema !== null) {
$items['schema'] = $this->schema;
}

return $items;
}

/**
* @return array<string, mixed[]>
*/
public function provide(): array
{
$items = [];

foreach ($this->joinColumns as $joinColumn) {
$items[$joinColumn->getShortName()] = $joinColumn->getAttributableItems();
}

foreach ($this->inverseJoinColumns as $inverseJoinColumn) {
$items['@ORM\InverseJoinColumn'] = $inverseJoinColumn->getAttributableItems();
}

return $items;
}

public function getAttributeClassName(): string
{
return PhpAttributeGroupFactory::TO_BE_ANNOUNCED;
}

/**
* @return string[]
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@
use Rector\BetterPhpDocParser\Printer\ArrayPartPhpDocTagPrinter;
use Rector\BetterPhpDocParser\Printer\TagValueNodePrinter;
use Rector\BetterPhpDocParser\ValueObject\PhpDocNode\Doctrine\AbstractDoctrineTagValueNode;
use Rector\PhpAttribute\Contract\PhpAttributableTagNodeInterface;
use Rector\PhpAttribute\Printer\PhpAttributeGroupFactory;

final class ManyToManyTagValueNode extends AbstractDoctrineTagValueNode implements ToManyTagNodeInterface, MappedByNodeInterface, InversedByNodeInterface, PhpAttributableTagNodeInterface
final class ManyToManyTagValueNode extends AbstractDoctrineTagValueNode implements ToManyTagNodeInterface, MappedByNodeInterface, InversedByNodeInterface
{
/**
* @var string
Expand Down Expand Up @@ -76,9 +74,4 @@ public function getShortName(): string
{
return '@ORM\ManyToMany';
}

public function getAttributeClassName(): string
{
return PhpAttributeGroupFactory::TO_BE_ANNOUNCED;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@
use Rector\BetterPhpDocParser\Contract\PhpDocNode\ShortNameAwareTagInterface;
use Rector\BetterPhpDocParser\Contract\PhpDocNode\SilentKeyNodeInterface;
use Rector\BetterPhpDocParser\ValueObject\PhpDocNode\AbstractTagValueNode;
use Rector\PhpAttribute\Contract\PhpAttributableTagNodeInterface;

/**
* @see \Rector\Tests\BetterPhpDocParser\PhpDocParser\TagValueNodeReprint\TagValueNodeReprintTest
*/
final class SymfonyRouteTagValueNode extends AbstractTagValueNode implements ShortNameAwareTagInterface, SilentKeyNodeInterface, PhpAttributableTagNodeInterface, ClassNameAwareTagInterface
final class SymfonyRouteTagValueNode extends AbstractTagValueNode implements ShortNameAwareTagInterface, SilentKeyNodeInterface, ClassNameAwareTagInterface
{
/**
* @var string
Expand Down Expand Up @@ -59,19 +58,6 @@ public function mimicTagValueNodeConfiguration(AbstractTagValueNode $abstractTag
$this->tagValueNodeConfiguration->mimic($abstractTagValueNode->tagValueNodeConfiguration);
}

/**
* @return mixed[]
*/
public function getAttributableItems(): array
{
return $this->filterOutMissingItems($this->items);
}

public function getAttributeClassName(): string
{
return self::CLASS_NAME;
}

public function getClassName(): string
{
return self::CLASS_NAME;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@
use Rector\BetterPhpDocParser\Contract\PhpDocNode\ShortNameAwareTagInterface;
use Rector\BetterPhpDocParser\Contract\PhpDocNode\SilentKeyNodeInterface;
use Rector\BetterPhpDocParser\ValueObject\PhpDocNode\AbstractTagValueNode;
use Rector\PhpAttribute\Contract\PhpAttributableTagNodeInterface;

/**
* @see \Rector\Tests\BetterPhpDocParser\PhpDocParser\TagValueNodeReprint\TagValueNodeReprintTest
*/
final class AssertEmailTagValueNode extends AbstractTagValueNode implements ShortNameAwareTagInterface, PhpAttributableTagNodeInterface, SilentKeyNodeInterface
final class AssertEmailTagValueNode extends AbstractTagValueNode implements ShortNameAwareTagInterface, SilentKeyNodeInterface
{
public function getShortName(): string
{
Expand All @@ -23,17 +22,4 @@ public function getSilentKey(): string
{
return 'choices';
}

/**
* @return mixed[]
*/
public function getAttributableItems(): array
{
return $this->filterOutMissingItems($this->items);
}

public function getAttributeClassName(): string
{
return 'Symfony\Component\Validator\Constraints\Email';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,11 @@

use Rector\BetterPhpDocParser\Contract\PhpDocNode\ShortNameAwareTagInterface;
use Rector\BetterPhpDocParser\ValueObject\PhpDocNode\AbstractTagValueNode;
use Rector\PhpAttribute\Contract\PhpAttributableTagNodeInterface;

final class AssertRangeTagValueNode extends AbstractTagValueNode implements ShortNameAwareTagInterface, PhpAttributableTagNodeInterface
final class AssertRangeTagValueNode extends AbstractTagValueNode implements ShortNameAwareTagInterface
{
public function getShortName(): string
{
return '@Assert\Range';
}

/**
* @return mixed[]
*/
public function getAttributableItems(): array
{
return $this->filterOutMissingItems($this->items);
}

public function getAttributeClassName(): string
{
return 'Symfony\Component\Validator\Constraints\Range';
}
}
Loading

0 comments on commit 6802663

Please sign in to comment.