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 |
||
8 | class GuzzleFactory |
||
9 | { |
||
10 | /** |
||
11 | * @param string $baseUri |
||
12 | * |
||
13 | * @return Guzzle |
||
14 | * |
||
15 | * @throws NotSupportedException when Guzzle vendor version is not supported. |
||
16 | */ |
||
17 | View Code Duplication | public static function createGuzzle($baseUri, $options) |
|
32 | |||
33 | /** |
||
34 | * @return int current Guzzle vendor version. |
||
35 | * |
||
36 | * @throws NotSupportedException when Guzzle vendor version is not supported. |
||
37 | */ |
||
38 | public static function detectGuzzleVersion() |
||
54 | |||
55 | /** |
||
56 | * @return bool |
||
57 | */ |
||
58 | private static function supportsGuzzle6() |
||
62 | |||
63 | /** |
||
64 | * @return bool |
||
65 | */ |
||
66 | private static function supportsGuzzle5() |
||
70 | |||
71 | /** |
||
72 | * @return bool |
||
73 | */ |
||
74 | private static function supportsGuzzle3() |
||
78 | |||
79 | View Code Duplication | public static function createMockedClient(array $mockedResponseCollection) |
|
94 | } |
||
95 |
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.