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 |
||
7 | class GuzzleFiveAdapter extends AbstractHttpAdapter |
||
8 | { |
||
9 | /** |
||
10 | * @var ClientInterface |
||
11 | */ |
||
12 | private $client; |
||
13 | |||
14 | /** |
||
15 | * Initialize class |
||
16 | * |
||
17 | * @param ClientInterface $client |
||
18 | * @param null $endpoint |
||
19 | */ |
||
20 | View Code Duplication | public function __construct(ClientInterface $client, $endpoint = NULL) |
|
28 | |||
29 | /** |
||
30 | * Perform an HTTP request on MusicBrainz |
||
31 | * |
||
32 | * @param string $path |
||
33 | * @param array $params |
||
34 | * @param array $options |
||
35 | * @param boolean $isAuthRequired |
||
36 | * @param boolean $returnArray |
||
37 | * |
||
38 | * @throws Exception |
||
39 | * @return array |
||
40 | */ |
||
41 | public function call($path, array $params = array(), array $options = array(), $isAuthRequired = FALSE, $returnArray = FALSE) |
||
74 | } |
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.