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 LibraryInformation implements LibraryInformationInterface |
||
| 26 | { |
||
| 27 | /** |
||
| 28 | * @var array |
||
| 29 | */ |
||
| 30 | private $additions = []; |
||
| 31 | /** |
||
| 32 | * @var array |
||
| 33 | */ |
||
| 34 | private $deprecations = []; |
||
| 35 | /** |
||
| 36 | * @var array |
||
| 37 | */ |
||
| 38 | private $removals = []; |
||
| 39 | |||
| 40 | /** |
||
| 41 | * Create a new instance and load default information |
||
| 42 | * |
||
| 43 | * This methods loads the changes.php file distributed with the library or phar. * |
||
| 44 | * |
||
| 45 | * @return static |
||
| 46 | */ |
||
| 47 | 40 | public static function createWithDefaults() |
|
| 53 | |||
| 54 | /** |
||
| 55 | * Create a new instance based on a given file path |
||
| 56 | * |
||
| 57 | * The filepath given to this method has to represent a php file returning |
||
| 58 | * an array with a valid structure. |
||
| 59 | * |
||
| 60 | * @param string $source Valid path to data source |
||
| 61 | * @return static |
||
| 62 | */ |
||
| 63 | 44 | public static function createFromFile($source) |
|
| 72 | |||
| 73 | |||
| 74 | /** |
||
| 75 | * Create a new instance using the supplied data |
||
| 76 | * |
||
| 77 | * @param array $data Array representation of data to represent |
||
| 78 | */ |
||
| 79 | 82 | public function __construct(array $data = []) |
|
| 96 | |||
| 97 | /** |
||
| 98 | * @inheritdoc |
||
| 99 | */ |
||
| 100 | 6 | public function toArray() |
|
| 108 | |||
| 109 | /** |
||
| 110 | * @inheritdoc |
||
| 111 | */ |
||
| 112 | 2 | public function mergeWith(LibraryInformationInterface $info) |
|
| 120 | |||
| 121 | /** |
||
| 122 | * @inheritdoc |
||
| 123 | */ |
||
| 124 | 40 | public function getFunctionInfo($name) |
|
| 128 | |||
| 129 | /** |
||
| 130 | * @inheritdoc |
||
| 131 | */ |
||
| 132 | 36 | public function getClassInfo($name) |
|
| 136 | |||
| 137 | /** |
||
| 138 | * @inheritdoc |
||
| 139 | */ |
||
| 140 | 26 | public function getConstantInfo($name) |
|
| 144 | |||
| 145 | /** |
||
| 146 | * @param string $name Name of the item |
||
| 147 | * @param string $type Type of the item (function, class or constant |
||
| 148 | * @return array An array in the format: |
||
| 149 | * <code> |
||
| 150 | * ['addition' => Version|null, 'deprecation' => Version|null, 'removal' => Version|null] |
||
| 151 | * </code> |
||
| 152 | */ |
||
| 153 | 58 | private function getInfo($name, $type) |
|
| 162 | } |
||
| 163 |