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 Execution |
||
12 | { |
||
13 | /** |
||
14 | * @var null|string |
||
15 | */ |
||
16 | private $name; |
||
17 | |||
18 | /** |
||
19 | * @var HttpClient |
||
20 | */ |
||
21 | private $client; |
||
22 | |||
23 | private $actions = [ |
||
24 | "abort" => ["xml"], // /api/V/execution/[ID]/abort |
||
25 | "output" => ["xml"], // /api/V/execution/[ID]/output |
||
26 | "output/state" => ["xml"], // /api/V/execution/[ID]/output/state |
||
27 | "state" => ["xml"], // /api/V/execution/[ID]/state |
||
28 | "input/files" => ["xml"], // /api/V/execution/[ID]/input/files |
||
29 | ]; |
||
30 | |||
31 | /** |
||
32 | * @param HttpClient $client |
||
33 | * @param string $name : Execution ID |
||
34 | */ |
||
35 | 15 | public function __construct(HttpClient $client, $name = null) |
|
40 | |||
41 | /** |
||
42 | * Find execution info by ID |
||
43 | * @param string $alt |
||
44 | * @return mixed |
||
45 | */ |
||
46 | 3 | public function find($alt = "xml") |
|
51 | |||
52 | /** |
||
53 | * Get Execution action |
||
54 | * @param $action |
||
55 | * @param string $alt xml|json |
||
56 | * @return array |
||
57 | * @throws \Exception |
||
58 | */ |
||
59 | 12 | View Code Duplication | public function get($action, $alt = "xml") |
71 | } |
||
72 |
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.