From 1751334845e28045cf47dd932a516f53cb53f09d Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Thu, 26 Sep 2019 16:03:14 +0200 Subject: [PATCH] add UniqueEntity stub, fix nullable name in IndexTagValueNode --- .../Class_/AbstractIndexTagValueNode.php | 6 +- .../Doctrine/ORM/Mapping/UniqueConstraint.php | 2 +- .../Validator/Constraints/UniqueEntity.php | 57 +++++++++++++++++++ 3 files changed, 61 insertions(+), 4 deletions(-) create mode 100644 stubs/Symfony/Bridge/Doctrine/Validator/Constraints/UniqueEntity.php diff --git a/packages/DoctrinePhpDocParser/src/Ast/PhpDoc/Class_/AbstractIndexTagValueNode.php b/packages/DoctrinePhpDocParser/src/Ast/PhpDoc/Class_/AbstractIndexTagValueNode.php index 93d242e2d27..caf4ef193ec 100644 --- a/packages/DoctrinePhpDocParser/src/Ast/PhpDoc/Class_/AbstractIndexTagValueNode.php +++ b/packages/DoctrinePhpDocParser/src/Ast/PhpDoc/Class_/AbstractIndexTagValueNode.php @@ -7,7 +7,7 @@ use Rector\DoctrinePhpDocParser\Ast\PhpDoc\AbstractDoctrineTagValueNode; abstract class AbstractIndexTagValueNode extends AbstractDoctrineTagValueNode { /** - * @var string + * @var string|null */ private $name; @@ -32,7 +32,7 @@ abstract class AbstractIndexTagValueNode extends AbstractDoctrineTagValueNode * @param mixed[]|null $options */ public function __construct( - string $name, + ?string $name, ?array $columns, ?array $flags, ?array $options, @@ -52,7 +52,7 @@ abstract class AbstractIndexTagValueNode extends AbstractDoctrineTagValueNode { $contentItems = []; - if ($this->name !== null) { + if ($this->name) { $contentItems['name'] = sprintf('name="%s"', $this->name); } diff --git a/stubs/Doctrine/ORM/Mapping/UniqueConstraint.php b/stubs/Doctrine/ORM/Mapping/UniqueConstraint.php index ac343bcbbae..dd0d17201ed 100644 --- a/stubs/Doctrine/ORM/Mapping/UniqueConstraint.php +++ b/stubs/Doctrine/ORM/Mapping/UniqueConstraint.php @@ -12,7 +12,7 @@ if (class_exists('Doctrine\ORM\Mapping\UniqueConstraint')) { */ final class UniqueConstraint implements Annotation { - /** @var string */ + /** @var string|null */ public $name; /** @var string[] */ diff --git a/stubs/Symfony/Bridge/Doctrine/Validator/Constraints/UniqueEntity.php b/stubs/Symfony/Bridge/Doctrine/Validator/Constraints/UniqueEntity.php new file mode 100644 index 00000000000..310f74ab54f --- /dev/null +++ b/stubs/Symfony/Bridge/Doctrine/Validator/Constraints/UniqueEntity.php @@ -0,0 +1,57 @@ + 'NOT_UNIQUE_ERROR', + ]; + + public function getRequiredOptions() + { + return ['fields']; + } + + /** + * The validator must be defined as a service with this name. + * + * @return string + */ + public function validatedBy() + { + return $this->service; + } + + /** + * {@inheritdoc} + */ + public function getTargets() + { + return self::CLASS_CONSTRAINT; + } + + public function getDefaultOption() + { + return 'fields'; + } +}