Total Complexity | 9 |
Total Lines | 87 |
Duplicated Lines | 11.49 % |
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 UserRegistrationResult extends RegistrationResult |
||
12 | { |
||
13 | /** |
||
14 | * @var string |
||
15 | */ |
||
16 | private $tenant; |
||
17 | |||
18 | /** |
||
19 | * @var string |
||
20 | */ |
||
21 | private $scope; |
||
22 | |||
23 | /** |
||
24 | * @var string |
||
25 | */ |
||
26 | private $sub; |
||
27 | |||
28 | /** |
||
29 | * UserRegistrationResult constructor. |
||
30 | * |
||
31 | * @param array $params |
||
32 | */ |
||
33 | View Code Duplication | public function __construct(array $params) |
|
|
|||
34 | { |
||
35 | parent::__construct($params); |
||
36 | |||
37 | $this->validateParams($params, ['tenant', 'sub']); |
||
38 | |||
39 | $this->setTenant($params['tenant']); |
||
40 | $this->setSub($params['sub']); |
||
41 | $this->setScope($params['scope'] ?? ''); |
||
42 | } |
||
43 | |||
44 | /** |
||
45 | * @return string |
||
46 | */ |
||
47 | public function getTenant(): string |
||
50 | } |
||
51 | |||
52 | /** |
||
53 | * @return string |
||
54 | */ |
||
55 | public function getScope(): string |
||
56 | { |
||
57 | return $this->scope; |
||
58 | } |
||
59 | |||
60 | /** |
||
61 | * @return string |
||
62 | */ |
||
63 | public function getSub(): string |
||
64 | { |
||
65 | return $this->sub; |
||
66 | } |
||
67 | |||
68 | /** |
||
69 | * @param string $tenant |
||
70 | */ |
||
71 | private function setTenant(string $tenant) |
||
72 | { |
||
73 | if (empty($tenant)) { |
||
74 | throw new InvalidArgumentException('Tenant value can not be empty'); |
||
75 | } |
||
76 | |||
77 | $this->tenant = $tenant; |
||
78 | } |
||
79 | |||
80 | /** |
||
81 | * @param string $scope |
||
82 | */ |
||
83 | private function setScope(string $scope) |
||
86 | } |
||
87 | |||
88 | /** |
||
89 | * @param string $sub |
||
90 | */ |
||
91 | private function setSub(string $sub) |
||
98 | } |
||
99 | } |
||
100 |
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.