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 |
||
| 14 | class RowMapperManager |
||
| 15 | { |
||
| 16 | |||
| 17 | /** |
||
| 18 | * @var string[] |
||
| 19 | */ |
||
| 20 | protected $rowMapperClasses = []; |
||
| 21 | |||
| 22 | /** |
||
| 23 | * @var Connection |
||
| 24 | */ |
||
| 25 | protected $dbConn; |
||
| 26 | |||
| 27 | /** |
||
| 28 | * @var RowMapperInterface[] |
||
| 29 | */ |
||
| 30 | protected $rowMappers; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * RowMapperManager constructor. |
||
| 34 | * @param Connection $dbConn |
||
| 35 | * @param \string[] $rowMapperClasses |
||
| 36 | */ |
||
| 37 | public function __construct(Connection $dbConn, array $rowMapperClasses) |
||
| 50 | |||
| 51 | /** |
||
| 52 | * Get the registered row mapper with the specified short name |
||
| 53 | * |
||
| 54 | * @param $shortName |
||
| 55 | * @return null|RowMapperInterface |
||
| 56 | */ |
||
| 57 | public function getRowMapperByShortName($shortName) |
||
| 62 | |||
| 63 | /** |
||
| 64 | * Get the registered row mapper with the specified short name |
||
| 65 | * |
||
| 66 | * @param $shortName |
||
| 67 | * @return null|RowMapperInterface |
||
| 68 | */ |
||
| 69 | public function getRowMapperClassByShortName($shortName) |
||
| 74 | |||
| 75 | public function getRowMapperShortNames() |
||
| 79 | |||
| 80 | /** |
||
| 81 | * @return RowMapperInterface[] |
||
| 82 | */ |
||
| 83 | public function getRowMappers() |
||
| 87 | |||
| 88 | /** |
||
| 89 | * Ensure that provided classname is a valid RowMapperInterface |
||
| 90 | * |
||
| 91 | * @param $rowMapperClass |
||
| 92 | * @throws \InvalidArgumentException |
||
| 93 | */ |
||
| 94 | View Code Duplication | protected function validateClass($rowMapperClass) |
|
| 105 | } |
||
| 106 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..