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...
18
{
19
/**
20
* @var int
21
*/
22
private $id;
23
24
/**
25
* @var string
26
*/
27
private $username;
28
29
/**
30
* @var string[]
31
*/
32
private $roles;
33
34
/**
35
* @var bool
36
*/
37
private $enabled;
38
39
/**
40
* User constructor.
41
*
42
* @param string[] $roles
43
*/
44
private function __construct(int $id, string $username, $roles, bool $enabled)
45
{
46
$this->id = $id;
47
$this->username = $username;
48
$this->roles = $roles;
49
$this->enabled = $enabled;
50
}
51
52
/**
53
* @return User
54
*/
55
public static function createFromArray(array $data): self
56
{
57
$id = -1;
58
59
if (isset($data['id'])) {
60
$id = $data['id'];
61
}
62
63
$username = '';
64
if (isset($data['username'])) {
65
$username = $data['username'];
66
}
67
68
$roles = [];
69
if (isset($data['roles'])) {
70
$roles = $data['roles'];
71
}
72
73
$enabled = false;
74
if (isset($data['enabled'])) {
75
$enabled = $data['enabled'];
76
}
77
78
return new self($id, $username, $roles, $enabled);
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.