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 JSONLoader extends AbstractLoader |
||
| 26 | { |
||
| 27 | |||
| 28 | /** |
||
| 29 | * Load the configuration from an URI. |
||
| 30 | * |
||
| 31 | * @since 0.4.0 |
||
| 32 | * |
||
| 33 | * @param string $uri URI of the resource to load. |
||
| 34 | * |
||
| 35 | * @return array Data contained within the resource. |
||
|
|
|||
| 36 | */ |
||
| 37 | 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 | protected function loadUri($uri) |
||
| 74 | |||
| 75 | /** |
||
| 76 | * Validate and return the URI. |
||
| 77 | * |
||
| 78 | * @since 0.4.0 |
||
| 79 | * |
||
| 80 | * @param string $uri URI of the resource to load. |
||
| 81 | * |
||
| 82 | * @return string Validated URI. |
||
| 83 | * @throws FailedToLoadConfigException If the URI does not exist or is not readable. |
||
| 84 | */ |
||
| 85 | View Code Duplication | protected function validateUri($uri) |
|
| 98 | } |
||
| 99 |
This check compares the return type specified in the
@returnannotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.