mirror of
https://github.com/rectorphp/rector.git
synced 2025-02-13 12:33:52 +01:00
add UniqueEntity stub, fix nullable name in IndexTagValueNode
This commit is contained in:
parent
e40f610399
commit
1751334845
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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[] */
|
||||
|
@ -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';
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user