Completed
Push — master ( 2e9ff7...454a32 )
by Alexis
07:25
created

User::loadValidatorMetadata()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 8

Duplication

Lines 13
Ratio 100 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 13
loc 13
rs 9.4285
cc 1
eloc 8
nc 1
nop 1
1
<?php
2
3
namespace AWurth\SilexUser\Document;
4
5
use AWurth\SilexUser\Model\User as BaseUser;
6
use AWurth\SilexUser\Validator\Constraints\Unique;
7
use DateTime;
8
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
9
use Symfony\Component\Validator\Mapping\ClassMetadata;
10
11
/**
12
 * Base User document class.
13
 *
14
 * @author Alexis Wurth <[email protected]>
15
 *
16
 * @ODM\MappedSuperclass
17
 */
18 View Code Duplication
abstract class User extends BaseUser
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
19
{
20
    /**
21
     * @var int
22
     *
23
     * @ODM\Id
24
     */
25
    protected $id;
26
27
    /**
28
     * @var string
29
     *
30
     * @ODM\Field(type="string")
31
     */
32
    protected $username;
33
34
    /**
35
     * @var string
36
     *
37
     * @ODM\Field(type="string")
38
     */
39
    protected $email;
40
41
    /**
42
     * @var string
43
     *
44
     * @ODM\Field(type="string")
45
     */
46
    protected $password;
47
48
    /**
49
     * @var string
50
     *
51
     * @ODM\Field(type="string")
52
     */
53
    protected $salt;
54
55
    /**
56
     * @var bool
57
     *
58
     * @ODM\Field(type="boolean")
59
     */
60
    protected $enabled = false;
61
62
    /**
63
     * @var DateTime
64
     *
65
     * @ODM\Field(type="date")
66
     */
67
    protected $lastLogin;
68
69
    /**
70
     * @var array
71
     *
72
     * @ODM\Field(type="collection")
73
     */
74
    protected $roles = [];
75
76
    /**
77
     * @var string
78
     *
79
     * @ODM\Field(type="string")
80
     */
81
    protected $confirmationToken;
82
83
    /**
84
     * {@inheritdoc}
85
     */
86
    public static function loadValidatorMetadata(ClassMetadata $metadata)
87
    {
88
        $metadata->addConstraint(new Unique([
89
            'fields' => 'username',
90
            'message' => 'silex_user.username.already_used'
91
        ]));
92
        $metadata->addConstraint(new Unique([
93
            'fields' => 'email',
94
            'message' => 'silex_user.email.already_used'
95
        ]));
96
97
        parent::loadValidatorMetadata($metadata);
98
    }
99
}
100