Total Complexity | 11 |
Total Lines | 109 |
Duplicated Lines | 10.09 % |
Changes | 0 |
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 |
||
11 | class UserTokenVerificationResult extends VerificationResult |
||
12 | { |
||
13 | /** |
||
14 | * @var string |
||
15 | */ |
||
16 | private $scope; |
||
17 | |||
18 | /** |
||
19 | * @var string |
||
20 | */ |
||
21 | private $deviceId; |
||
22 | |||
23 | /** |
||
24 | * @var string |
||
25 | */ |
||
26 | private $sub; |
||
27 | |||
28 | /** |
||
29 | * @var int |
||
30 | */ |
||
31 | private $exp; |
||
32 | |||
33 | /** |
||
34 | * UserTokenVerificationResult constructor. |
||
35 | * |
||
36 | * @param array $params |
||
37 | */ |
||
38 | View Code Duplication | public function __construct(array $params) |
|
|
|||
39 | { |
||
40 | parent::__construct($params); |
||
41 | |||
42 | $this->validateParams($params, ['deviceId', 'sub', 'exp']); |
||
43 | |||
44 | $this->setDeviceId($params['deviceId']); |
||
45 | $this->setSub($params['sub']); |
||
46 | $this->setExp($params['exp']); |
||
47 | $this->setScope($params['scope'] ?? ''); |
||
48 | } |
||
49 | |||
50 | /** |
||
51 | * @return string |
||
52 | */ |
||
53 | public function getScope(): string |
||
54 | { |
||
55 | return $this->scope; |
||
56 | } |
||
57 | |||
58 | /** |
||
59 | * @return string |
||
60 | */ |
||
61 | public function getDeviceId(): string |
||
62 | { |
||
63 | return $this->deviceId; |
||
64 | } |
||
65 | |||
66 | /** |
||
67 | * @return string |
||
68 | */ |
||
69 | public function getSub(): string |
||
70 | { |
||
71 | return $this->sub; |
||
72 | } |
||
73 | |||
74 | /** |
||
75 | * @return int |
||
76 | */ |
||
77 | public function getExp(): int |
||
78 | { |
||
79 | return $this->exp; |
||
80 | } |
||
81 | |||
82 | /** |
||
83 | * @param string $scope |
||
84 | */ |
||
85 | private function setScope(string $scope) |
||
86 | { |
||
87 | $this->scope = $scope; |
||
88 | } |
||
89 | |||
90 | /** |
||
91 | * @param string $deviceId |
||
92 | */ |
||
93 | private function setDeviceId(string $deviceId) |
||
94 | { |
||
95 | if (empty($deviceId)) { |
||
96 | throw new InvalidArgumentException('DeviceId value can not be empty'); |
||
97 | } |
||
98 | |||
99 | $this->deviceId = $deviceId; |
||
100 | } |
||
101 | |||
102 | /** |
||
103 | * @param string $sub |
||
104 | */ |
||
105 | private function setSub(string $sub) |
||
112 | } |
||
113 | |||
114 | /** |
||
115 | * @param int $exp |
||
116 | */ |
||
117 | private function setExp(int $exp) |
||
120 | } |
||
121 | } |
||
122 |
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.