User   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 84
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

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

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
/*
4
 * This file is part of the awurth/silex-user package.
5
 *
6
 * (c) Alexis Wurth <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace AWurth\Silex\User\Entity;
13
14
use AWurth\Silex\User\Model\User as BaseUser;
15
use DateTime;
16
use Doctrine\ORM\Mapping as ORM;
17
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
18
use Symfony\Component\Validator\Mapping\ClassMetadata;
19
20
/**
21
 * Base User entity class.
22
 *
23
 * @author Alexis Wurth <[email protected]>
24
 *
25
 * @ORM\MappedSuperclass
26
 */
27 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...
28
{
29
    /**
30
     * @var int
31
     *
32
     * @ORM\Id
33
     * @ORM\GeneratedValue
34
     * @ORM\Column(name="id", type="integer")
35
     */
36
    protected $id;
37
38
    /**
39
     * @var string
40
     *
41
     * @ORM\Column(name="username", type="string", length=180, unique=true)
42
     */
43
    protected $username;
44
45
    /**
46
     * @var string
47
     *
48
     * @ORM\Column(name="email", type="string", length=180, unique=true)
49
     */
50
    protected $email;
51
52
    /**
53
     * @var string
54
     *
55
     * @ORM\Column(name="password", type="string", length=255)
56
     */
57
    protected $password;
58
59
    /**
60
     * @var string
61
     *
62
     * @ORM\Column(name="salt", type="string", length=255, nullable=true)
63
     */
64
    protected $salt;
65
66
    /**
67
     * @var bool
68
     *
69
     * @ORM\Column(name="enabled", type="boolean")
70
     */
71
    protected $enabled = false;
72
73
    /**
74
     * @var DateTime
75
     *
76
     * @ORM\Column(name="last_login", type="datetime", nullable=true)
77
     */
78
    protected $lastLogin;
79
80
    /**
81
     * @var array
82
     *
83
     * @ORM\Column(name="roles", type="array")
84
     */
85
    protected $roles = [];
86
87
    /**
88
     * @var string
89
     *
90
     * @ORM\Column(name="confirmation_token", type="string", length=180, unique=true, nullable=true)
91
     */
92
    protected $confirmationToken;
93
94
    /**
95
     * {@inheritdoc}
96
     */
97
    public static function loadValidatorMetadata(ClassMetadata $metadata)
98
    {
99
        $metadata->addConstraint(new UniqueEntity([
100
            'fields' => 'username',
101
            'message' => 'silex_user.username.already_used'
102
        ]));
103
        $metadata->addConstraint(new UniqueEntity([
104
            'fields' => 'email',
105
            'message' => 'silex_user.email.already_used'
106
        ]));
107
108
        parent::loadValidatorMetadata($metadata);
109
    }
110
}
111