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 |
||
| 28 | class LegacyDFSCluster implements IOMetadataHandler |
||
| 29 | { |
||
| 30 | /** @var Connection */ |
||
| 31 | private $db; |
||
| 32 | |||
| 33 | /** @var UrlDecorator */ |
||
| 34 | private $urlDecorator; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * @param Connection $connection Doctrine DBAL connection |
||
| 38 | * @param UrlDecorator $urlDecorator The URL decorator used to add a prefix to files path |
||
| 39 | */ |
||
| 40 | public function __construct(Connection $connection, UrlDecorator $urlDecorator = null) |
||
| 45 | |||
| 46 | /** |
||
| 47 | * Inserts a new reference to file $spiBinaryFileId. |
||
| 48 | * |
||
| 49 | * @param string $spiBinaryFileId |
||
|
|
|||
| 50 | * |
||
| 51 | * @throws RuntimeException if a DBAL error occurs |
||
| 52 | * |
||
| 53 | * @return \eZ\Publish\SPI\IO\BinaryFile |
||
| 54 | */ |
||
| 55 | public function create(SPIBinaryFileCreateStruct $binaryFileCreateStruct) |
||
| 92 | |||
| 93 | /** |
||
| 94 | * Deletes file $spiBinaryFileId. |
||
| 95 | * |
||
| 96 | * @throws BinaryFileNotFoundException If $spiBinaryFileId is not found |
||
| 97 | * |
||
| 98 | * @param string $spiBinaryFileId |
||
| 99 | */ |
||
| 100 | View Code Duplication | public function delete($spiBinaryFileId) |
|
| 114 | |||
| 115 | /** |
||
| 116 | * Loads and returns metadata for $spiBinaryFileId. |
||
| 117 | * |
||
| 118 | * @param string $spiBinaryFileId |
||
| 119 | * |
||
| 120 | * @return SPIBinaryFile |
||
| 121 | * |
||
| 122 | * @throws BinaryFileNotFoundException if no row is found for $spiBinaryFileId |
||
| 123 | * @throws DBALException Any unhandled DBAL exception |
||
| 124 | */ |
||
| 125 | public function load($spiBinaryFileId) |
||
| 141 | |||
| 142 | /** |
||
| 143 | * Checks if a file $spiBinaryFileId exists. |
||
| 144 | * |
||
| 145 | * @param string $spiBinaryFileId |
||
| 146 | * |
||
| 147 | * @throws NotFoundException |
||
| 148 | * @throws DBALException Any unhandled DBAL exception |
||
| 149 | * |
||
| 150 | * @return bool |
||
| 151 | */ |
||
| 152 | View Code Duplication | public function exists($spiBinaryFileId) |
|
| 162 | |||
| 163 | /** |
||
| 164 | * @param SPIBinaryFileCreateStruct $binaryFileCreateStruct |
||
| 165 | * |
||
| 166 | * @return mixed |
||
| 167 | */ |
||
| 168 | protected function getNameTrunk(SPIBinaryFileCreateStruct $binaryFileCreateStruct) |
||
| 172 | |||
| 173 | /** |
||
| 174 | * Returns the value for the scope meta field, based on the created file's path. |
||
| 175 | * |
||
| 176 | * Note that this is slightly incorrect, as it will return binaryfile for media files as well. It is a bit |
||
| 177 | * of an issue, but shouldn't be a blocker given that this meta field isn't used that much. |
||
| 178 | * |
||
| 179 | * @param SPIBinaryFileCreateStruct $binaryFileCreateStruct |
||
| 180 | * |
||
| 181 | * @return string |
||
| 182 | */ |
||
| 183 | protected function getScope(SPIBinaryFileCreateStruct $binaryFileCreateStruct) |
||
| 197 | |||
| 198 | /** |
||
| 199 | * Adds the internal prefix string to $id. |
||
| 200 | * |
||
| 201 | * @param string $id |
||
| 202 | * |
||
| 203 | * @return string prefixed id |
||
| 204 | */ |
||
| 205 | protected function addPrefix($id) |
||
| 209 | |||
| 210 | /** |
||
| 211 | * Removes the internal prefix string from $prefixedId. |
||
| 212 | * |
||
| 213 | * @param string $prefixedId |
||
| 214 | * |
||
| 215 | * @return string the id without the prefix |
||
| 216 | * |
||
| 217 | * @throws InvalidBinaryFileIdException if the prefix isn't found in $prefixedId |
||
| 218 | */ |
||
| 219 | protected function removePrefix($prefixedId) |
||
| 223 | |||
| 224 | View Code Duplication | public function getMimeType($spiBinaryFileId) |
|
| 238 | |||
| 239 | public function deleteDirectory($spiPath) |
||
| 245 | |||
| 246 | /** |
||
| 247 | * Maps an array of data base properties (id, size, mtime, datatype, md5_path, path...) to an SPIBinaryFile object. |
||
| 248 | * |
||
| 249 | * @param array $properties database properties array |
||
| 250 | * |
||
| 251 | * @return SPIBinaryFile |
||
| 252 | */ |
||
| 253 | View Code Duplication | protected function mapArrayToSPIBinaryFile(array $properties) |
|
| 263 | |||
| 264 | /** |
||
| 265 | * @param SPIBinaryFileCreateStruct $binaryFileCreateStruct |
||
| 266 | * |
||
| 267 | * @return SPIBinaryFile |
||
| 268 | */ |
||
| 269 | protected function mapSPIBinaryFileCreateStructToSPIBinaryFile(SPIBinaryFileCreateStruct $binaryFileCreateStruct) |
||
| 279 | |||
| 280 | public function loadList($limit = null, $offset = null) |
||
| 305 | |||
| 306 | public function count() |
||
| 315 | } |
||
| 316 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italyis not defined by the methodfinale(...).The most likely cause is that the parameter was removed, but the annotation was not.