Completed
Pull Request — master (#234)
by jelmer
05:16
created

UniqueDataTransferObject   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
lcom 0
cbo 1
dl 0
loc 45
rs 10
c 1
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getRequiredOptions() 0 4 1
A validatedBy() 0 4 1
A getTargets() 0 4 1
A getDefaultOption() 0 4 1
1
<?php
2
3
namespace SumoCoders\FrameworkCoreBundle\Validator;
4
5
use Symfony\Component\Validator\Constraint;
6
7
/**
8
 * Constraint for the Unique Entity validator.
9
 *
10
 * @Annotation
11
 * @Target({"CLASS", "ANNOTATION"})
12
 */
13
class UniqueDataTransferObject extends Constraint
14
{
15
    const NOT_UNIQUE_ERROR = '23bd9dbf-6b9b-41cd-a99e-4844bcf3077f';
16
17
    public $message = 'This value is already used.';
18
    public $service = 'unique_data_transfer_object';
19
    public $em = null;
20
    public $entityClass = null;
21
    public $repositoryMethod = 'findBy';
22
    public $fields = array();
23
    public $errorPath = null;
24
    public $ignoreNull = true;
25
26
    protected static $errorNames = array(
27
        self::NOT_UNIQUE_ERROR => 'NOT_UNIQUE_ERROR',
28
    );
29
30
    public function getRequiredOptions()
31
    {
32
        return array('fields');
33
    }
34
35
    /**
36
     * The validator must be defined as a service with this name.
37
     *
38
     * @return string
39
     */
40
    public function validatedBy()
41
    {
42
        return $this->service;
43
    }
44
45
    /**
46
     * {@inheritdoc}
47
     */
48
    public function getTargets()
49
    {
50
        return self::CLASS_CONSTRAINT;
51
    }
52
53
    public function getDefaultOption()
54
    {
55
        return 'fields';
56
    }
57
}
58