Completed
Push — sf2.7 ( 18de34...b252b6 )
by Laurent
18:26
created

User::setGroups()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 2
eloc 3
nc 2
nop 1
1
<?php
2
// src/AppBundle/Entity/User.php
3
 
4
namespace AppBundle\Entity;
5
 
6
use FOS\UserBundle\Model\User as BaseUser;
7
use Doctrine\ORM\Mapping as ORM;
8
use Doctrine\Common\Collections\ArrayCollection;
9
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
10
 
11
/**
12
 * @ORM\Entity
13
 * @ORM\Table(name="fos_user")
14
 * @UniqueEntity(fields="usernameCanonical", errorPath="username", message="fos_user.username.already_used", groups={"Default", "Registration", "Profile"})
15
 * @UniqueEntity(fields="emailCanonical", errorPath="email", message="fos_user.email.already_used", groups={"Default", "Registration", "Profile"})
16
 */
17
class User extends BaseUser {
18
 
19
    /**
20
     * @ORM\Id
21
     * @ORM\Column(type="integer")
22
     * @ORM\GeneratedValue(strategy="AUTO")
23
     */
24
    protected $id;
25
 
26
    /**
27
     * @ORM\ManyToMany(targetEntity="AppBundle\Entity\Group", inversedBy="users")
28
     * @ORM\JoinTable(name="fos_user_user_group",
29
     *      joinColumns={@ORM\JoinColumn(name="user_id", referencedColumnName="id")},
30
     *      inverseJoinColumns={@ORM\JoinColumn(name="group_id", referencedColumnName="id")}
31
     * )
32
     */
33
    protected $groups;
34
 
35
    /**
36
     * @ORM\Column(type="integer", length=6, options={"default":0})
37
     */
38
    protected $loginCount = 0;
39
 
40
    /**
41
     * @var \DateTime
42
     *
43
     * @ORM\Column(type="datetime", nullable=true)
44
     */
45
    protected $firstLogin;
46
 
47
    public function __construct() {
48
        parent::__construct();
49
        $this->groups = new ArrayCollection();
50
    }
51
 
52
    /**
53
     * Set loginCount
54
     *
55
     * @param integer $loginCount
56
     *
57
     * @return User
58
     */
59
    public function setLoginCount($loginCount) {
60
        $this->loginCount = $loginCount;
61
        return $this;
62
    }
63
 
64
    /**
65
     * Get loginCount
66
     *
67
     * @return integer
68
     */
69
    public function getLoginCount() {
70
        return $this->loginCount;
71
    }
72
 
73
    /**
74
     * Set firstLogin
75
     *
76
     * @param \DateTime $firstLogin
77
     *
78
     * @return User
79
     */
80
    public function setFirstLogin($firstLogin) {
81
        $this->firstLogin = $firstLogin;
82
        return $this;
83
    }
84
 
85
    /**
86
     * Get firstLogin
87
     *
88
     * @return \DateTime
89
     */
90
    public function getFirstLogin() {
91
        return $this->firstLogin;
92
    }
93
 
94
    function getEnabled() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
95
        return $this->enabled;
96
    }
97
 
98
    function getLocked() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
99
        return $this->locked;
100
    }
101
 
102
    function getExpired() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
103
        return $this->expired;
104
    }
105
 
106
    function getExpiresAt() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
107
        return $this->expiresAt;
108
    }
109
 
110
    function getCredentialsExpired() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
111
        return $this->credentialsExpired;
112
    }
113
 
114
    function getCredentialsExpireAt() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
115
        return $this->credentialsExpireAt;
116
    }
117
 
118
    function setSalt($salt) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
119
        $this->salt = $salt;
120
    }
121
 
122
    public function setPassword($password) {
123
        if ($password !== null) {
124
            $this->password = $password;
125
        }
126
        return $this;
127
    }
128
 
129
    function setGroups(Collection $groups = null) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
130
        if ($groups !== null) {
131
            $this->groups = $groups;
132
        }
133
    }
134
 
135
    public function setRoles(array $roles = array()) {
136
        $this->roles = array();
137
        foreach ($roles as $role) {
138
            $this->addRole($role);
139
        }
140
        return $this;
141
    }
142
 
143
    public function hasGroup($name = '') {
144
        return in_array($name, $this->getGroupNames());
145
    }
146
 
147
}