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 |
||
13 | View Code Duplication | class Libraries extends LazyResourceList implements \ArrayAccess, \Countable, \Iterator |
|
|
|||
14 | { |
||
15 | use ReadOnlyArrayAccess; |
||
16 | use IterableCollection; |
||
17 | |||
18 | /** |
||
19 | * Locations constructor. |
||
20 | * |
||
21 | * @param Client $client |
||
22 | */ |
||
23 | public function __construct(Client $client) |
||
27 | |||
28 | /** |
||
29 | * Get a single library by its library code. |
||
30 | * |
||
31 | * @param string $code |
||
32 | * |
||
33 | * @return Library |
||
34 | */ |
||
35 | public function get($code) |
||
39 | |||
40 | /** |
||
41 | * Convert a data element to a resource object. |
||
42 | * |
||
43 | * @param $data |
||
44 | * |
||
45 | * @return Library |
||
46 | */ |
||
47 | protected function convertToResource($data) |
||
52 | |||
53 | /** |
||
54 | * Generate the base URL for this resource. |
||
55 | * |
||
56 | * @return string |
||
57 | */ |
||
58 | protected function urlBase() |
||
62 | } |
||
63 |
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.