MajimaUser::isEqualTo()   B
last analyzed

Complexity

Conditions 5
Paths 5

Size

Total Lines 19
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 9
nc 5
nop 1
dl 0
loc 19
rs 8.8571
c 0
b 0
f 0
1
<?php
2
/**
3
 * Copyright (c) 2017
4
 *
5
 * @package   Majima
6
 * @author    David Neustadt <[email protected]>
7
 * @copyright 2017 David Neustadt
8
 * @license   MIT
9
 */
10
11
namespace Majima\Security;
12
13
use Symfony\Component\Security\Core\User\UserInterface;
14
use Symfony\Component\Security\Core\User\EquatableInterface;
15
16
/**
17
 * Class MajimaUser
18
 * @package Majima\Security
19
 */
20
class MajimaUser implements UserInterface, EquatableInterface
21
{
22
    /**
23
     * @var string
24
     */
25
    private $username;
26
27
    /**
28
     * @var string
29
     */
30
    private $password;
31
32
    /**
33
     * @var string
34
     */
35
    private $salt;
36
37
    /**
38
     * @var array
39
     */
40
    private $roles;
41
42
    /**
43
     * MajimaUser constructor.
44
     * @param $username
45
     * @param $password
46
     * @param $salt
47
     * @param array $roles
48
     */
49
    public function __construct($username, $password, $salt, array $roles)
50
    {
51
        $this->username = $username;
52
        $this->password = $password;
53
        $this->salt = $salt;
54
        $this->roles = $roles;
55
    }
56
57
    /**
58
     * @return array
59
     */
60
    public function getRoles()
61
    {
62
        return $this->roles;
63
    }
64
65
    /**
66
     * @return string
67
     */
68
    public function getPassword()
69
    {
70
        return $this->password;
71
    }
72
73
    /**
74
     * @return string
75
     */
76
    public function getSalt()
77
    {
78
        return $this->salt;
79
    }
80
81
    /**
82
     * @return string
83
     */
84
    public function getUsername()
85
    {
86
        return $this->username;
87
    }
88
89
    public function eraseCredentials()
90
    {
91
    }
92
93
    /**
94
     * @param UserInterface $user
95
     * @return bool
96
     */
97
    public function isEqualTo(UserInterface $user)
98
    {
99
        if (!$user instanceof MajimaUser) {
100
            return false;
101
        }
102
103
        if ($this->password !== $user->getPassword()) {
104
            return false;
105
        }
106
107
        if ($this->salt !== $user->getSalt()) {
108
            return false;
109
        }
110
111
        if ($this->username !== $user->getUsername()) {
112
            return false;
113
        }
114
115
        return true;
116
    }
117
}