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 |
||
14 | View Code Duplication | class JobInstances extends SimplePaginatedList implements \ArrayAccess, \Countable, \Iterator |
|
|
|||
15 | { |
||
16 | use ReadOnlyArrayAccess; |
||
17 | use IterableCollection; |
||
18 | |||
19 | /** @var Job */ |
||
20 | public $job; |
||
21 | |||
22 | /** |
||
23 | * Job Instances constructor. |
||
24 | * |
||
25 | * @param Client $client |
||
26 | * @param Job $job |
||
27 | */ |
||
28 | public function __construct(Client $client, Job $job) |
||
33 | |||
34 | /** |
||
35 | * Get a single Job Instance by its instance_id. |
||
36 | * |
||
37 | * @param string $instance_id |
||
38 | * |
||
39 | * @return JobInstance |
||
40 | */ |
||
41 | public function get(string $instance_id) |
||
45 | |||
46 | /** |
||
47 | * Convert a data element to a resource object. |
||
48 | * |
||
49 | * @param $data |
||
50 | * |
||
51 | * @return JobInstance |
||
52 | */ |
||
53 | protected function convertToResource($data) |
||
58 | |||
59 | /** |
||
60 | * Generate the base URL for this resource. |
||
61 | * |
||
62 | * @return string |
||
63 | */ |
||
64 | protected function urlBase() |
||
68 | } |
||
69 |
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.