DisableAccountTrait   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 45
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A canAccountBeDisabled() 0 3 1
A isEnabled() 0 3 2
A setEnabled() 0 7 2
1
<?php
2
3
//----------------------------------------------------------------------
4
//
5
//  Copyright (C) 2017-2018 Artem Rodygin
6
//
7
//  You should have received a copy of the MIT License along with
8
//  this file. If not, see <http://opensource.org/licenses/MIT>.
9
//
10
//----------------------------------------------------------------------
11
12
namespace LazySec\Entity;
13
14
use Doctrine\ORM\Mapping as ORM;
15
16
/**
17
 * Trait for "disable account" feature.
18
 */
19
trait DisableAccountTrait
20
{
21
    /**
22
     * @var bool Whether account is enabled.
23
     *
24
     * @ORM\Column(name="enabled", type="boolean", nullable=false)
25
     */
26
    protected $isEnabled = true;
27
28
    /**
29
     * Checks whether the user is enabled.
30
     *
31
     * Inherited from '\Symfony\Component\Security\Core\User\AdvancedUserInterface'.
32
     *
33
     * @return bool TRUE if the user is enabled, FALSE otherwise.
34
     */
35 4
    public function isEnabled(): bool
36
    {
37 4
        return $this->canAccountBeDisabled() ? $this->isEnabled : true;
38
    }
39
40
    /**
41
     * Disables or enables the account.
42
     *
43
     * @param bool $isEnabled New status of the account.
44
     *
45
     * @return self
46
     */
47 2
    public function setEnabled(bool $isEnabled): self
48
    {
49 2
        if ($this->canAccountBeDisabled()) {
50 2
            $this->isEnabled = $isEnabled;
51
        }
52
53 2
        return $this;
54
    }
55
56
    /**
57
     * Specifies whether the "disable account" feature is available for this user.
58
     *
59
     * @return bool
60
     */
61 4
    protected function canAccountBeDisabled(): bool
62
    {
63 4
        return true;
64
    }
65
}
66