User   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 87
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 10
lcom 0
cbo 0
dl 87
loc 87
ccs 0
cts 43
cp 0
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 7 7 1
A createFromArray() 25 25 5
A getId() 4 4 1
A getUsername() 4 4 1
A getRoles() 4 4 1
A isEnabled() 4 4 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
declare(strict_types=1);
4
5
/*
6
 * This software may be modified and distributed under the terms
7
 * of the MIT license. See the LICENSE file for details.
8
 */
9
10
namespace FAPI\Sylius\Model\Customer;
11
12
use FAPI\Sylius\Model\CreatableFromArray;
13
14
/**
15
 * @author Kasim Taskin <[email protected]>
16
 */
17 View Code Duplication
final class User implements CreatableFromArray
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...
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);
79
    }
80
81
    public function getId(): int
82
    {
83
        return $this->id;
84
    }
85
86
    public function getUsername(): string
87
    {
88
        return $this->username;
89
    }
90
91
    /**
92
     * @return string[]
93
     */
94
    public function getRoles(): array
95
    {
96
        return $this->roles;
97
    }
98
99
    public function isEnabled(): bool
100
    {
101
        return $this->enabled;
102
    }
103
}
104