add UniqueEntity stub, fix nullable name in IndexTagValueNode

This commit is contained in:
Tomas Votruba 2019-09-26 16:03:14 +02:00
parent e40f610399
commit 1751334845
3 changed files with 61 additions and 4 deletions

View File

@ -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);
}

View File

@ -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[] */

View File

@ -0,0 +1,57 @@
<?php declare(strict_types=1);
namespace Symfony\Bridge\Doctrine\Validator\Constraints;
use Symfony\Component\Validator\Constraint;
if (class_exists('Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity')) {
return;
}
/**
* @Annotation
* @Target({"CLASS", "ANNOTATION"})
*/
class UniqueEntity extends Constraint
{
const NOT_UNIQUE_ERROR = '23bd9dbf-6b9b-41cd-a99e-4844bcf3077f';
public $message = 'This value is already used.';
public $service = 'doctrine.orm.validator.unique';
public $em = null;
public $entityClass = null;
public $repositoryMethod = 'findBy';
public $fields = [];
public $errorPath = null;
public $ignoreNull = true;
protected static $errorNames = [
self::NOT_UNIQUE_ERROR => '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';
}
}