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 | View Code Duplication | class Representation extends LazyResource |
|
|
|||
12 | { |
||
13 | /* @var string */ |
||
14 | public $representation_id; |
||
15 | |||
16 | /* @var Bib */ |
||
17 | public $bib; |
||
18 | |||
19 | /* @var Files */ |
||
20 | public $files; |
||
21 | |||
22 | public function __construct(Client $client, Bib $bib, $representation_id) |
||
29 | |||
30 | /** |
||
31 | * Generate the base URL for this resource. |
||
32 | * |
||
33 | * @return string |
||
34 | */ |
||
35 | protected function urlBase() |
||
39 | |||
40 | /** |
||
41 | * Get the files for this representation. |
||
42 | */ |
||
43 | public function getFiles() |
||
47 | |||
48 | /** |
||
49 | * Check if we have the full representation of our data object. |
||
50 | * |
||
51 | * @param \stdClass $data |
||
52 | * |
||
53 | * @return bool |
||
54 | */ |
||
55 | protected function isInitialized($data) |
||
59 | } |
||
60 |
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.