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 |
||
25 | class PHPLoader extends AbstractLoader |
||
26 | { |
||
27 | |||
28 | /** |
||
29 | * Check whether the loader is able to load a given URI. |
||
30 | * |
||
31 | * @since 0.4.0 |
||
32 | * |
||
33 | * @param string $uri URI to check. |
||
34 | * |
||
35 | * @return bool Whether the loader can load the given URI. |
||
36 | */ |
||
37 | 2 | public static function canLoad($uri) |
|
43 | |||
44 | /** |
||
45 | * Load the contents of an resource identified by an URI. |
||
46 | * |
||
47 | * @since 0.4.0 |
||
48 | * |
||
49 | * @param string $uri URI of the resource. |
||
50 | * |
||
51 | * @return array|null Raw data loaded from the resource. Null if no data found. |
||
52 | * @throws FailedToLoadConfigException If the resource could not be loaded. |
||
53 | */ |
||
54 | 2 | protected function loadUri($uri) |
|
76 | |||
77 | /** |
||
78 | * Validate and return the URI. |
||
79 | * |
||
80 | * @since 0.4.0 |
||
81 | * |
||
82 | * @param string $uri URI of the resource to load. |
||
83 | * |
||
84 | * @return string Validated URI. |
||
85 | * @throws FailedToLoadConfigException If the URI does not exist or is not readable. |
||
86 | */ |
||
87 | 2 | View Code Duplication | protected function validateUri($uri) |
100 | } |
||
101 |
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.