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

User   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 82
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 1
c 0
b 0
f 0
lcom 0
cbo 3
dl 82
loc 82
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A loadValidatorMetadata() 13 13 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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