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 |
||
20 | class Update implements Action, ActionGet, ActionSet |
||
21 | { |
||
22 | use ConstructorUrl, QueryBuilder, AuthenticationHelper; |
||
23 | |||
24 | protected $url = '?'; |
||
25 | |||
26 | /** |
||
27 | * Request type to created |
||
28 | * @var string |
||
29 | */ |
||
30 | protected $HTTP_TYPE = 'PUT'; |
||
31 | protected $data = []; |
||
32 | protected $kernel; |
||
33 | |||
34 | /** |
||
35 | * @param KernelBpm $bpm |
||
36 | * @return void |
||
37 | */ |
||
38 | 1 | public function injectionKernel(KernelBpm $bpm) |
|
39 | { |
||
40 | 1 | $this->kernel = $bpm; |
|
41 | 1 | } |
|
42 | |||
43 | /** |
||
44 | * @return string |
||
45 | */ |
||
46 | 2 | public function getUrl() |
|
50 | |||
51 | /** |
||
52 | * @param array $data |
||
53 | * @return array |
||
54 | */ |
||
55 | 2 | public function setData(array $data) |
|
59 | |||
60 | /** |
||
61 | * @return \agoalofalife\bpm\Contracts\Handler |
||
62 | */ |
||
63 | 1 | public function processData() |
|
64 | { |
||
65 | 1 | $this->query(); |
|
66 | 1 | return $this->kernel->getHandler(); |
|
67 | } |
||
68 | |||
69 | /** |
||
70 | * @return array |
||
71 | */ |
||
72 | 1 | public function getData() |
|
76 | |||
77 | /** |
||
78 | * @return mixed |
||
79 | */ |
||
80 | 1 | View Code Duplication | private function query() |
94 | |||
95 | } |
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.