Completed
Push — master ( 7e1219...640c4e )
by jelmer
05:37 queued 10s
created

UniqueDataTransferObject::getRequiredOptions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 4
rs 10
c 1
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace SumoCoders\FrameworkCoreBundle\Validator;
4
5
use Doctrine\ORM\EntityManagerInterface;
6
use Symfony\Component\Validator\Constraint;
7
8
/**
9
 * Constraint for the Unique Entity validator.
10
 *
11
 * @Annotation
12
 * @Target({"CLASS", "ANNOTATION"})
13
 */
14
class UniqueDataTransferObject extends Constraint
15
{
16
    const NOT_UNIQUE_ERROR = '23bd9dbf-6b9b-41cd-a99e-4844bcf3077f';
17
18
    /** @var string */
19
    public $message = 'This value is already used.';
20
21
    /** @var string */
22
    public $service = 'unique_data_transfer_object';
23
24
    /** @var EntityManagerInterface|null */
25
    public $em = null;
26
27
    /** @var mixed|null */
28
    public $entityClass = null;
29
30
    /** @var string */
31
    public $repositoryMethod = 'findBy';
32
33
    /** @var array */
34
    public $fields = array();
35
36
    /** @var string|null */
37
    public $errorPath = null;
38
39
    /** @var bool */
40
    public $ignoreNull = true;
41
42
    /**
43
     * @var array
44
     */
45
    protected static $errorNames = array(
46
        self::NOT_UNIQUE_ERROR => 'NOT_UNIQUE_ERROR',
47
    );
48
49
    public function getRequiredOptions(): array
50
    {
51
        return array('fields');
52
    }
53
54
    /**
55
     * The validator must be defined as a service with this name.
56
     *
57
     * @return string
58
     */
59
    public function validatedBy(): string
60
    {
61
        return $this->service;
62
    }
63
64
    /**
65
     * {@inheritdoc}
66
     */
67
    public function getTargets()
68
    {
69
        return self::CLASS_CONSTRAINT;
70
    }
71
72
    public function getDefaultOption(): string
73
    {
74
        return 'fields';
75
    }
76
}
77