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 |
||
| 21 | class YamlStorage implements Storage |
||
| 22 | { |
||
| 23 | /** |
||
| 24 | * The data collection. |
||
| 25 | * |
||
| 26 | * @var array |
||
| 27 | */ |
||
| 28 | private $data; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * Constructor. |
||
| 32 | * |
||
| 33 | * @param string $yamlFile The dir path of YAML file |
||
|
|
|||
| 34 | */ |
||
| 35 | public function __construct($yamlFile = null) |
||
| 45 | |||
| 46 | /** |
||
| 47 | * {@inheritdoc} |
||
| 48 | */ |
||
| 49 | View Code Duplication | public function findAll($limit, $offset) |
|
| 62 | |||
| 63 | /** |
||
| 64 | * {@inheritdoc} |
||
| 65 | */ |
||
| 66 | View Code Duplication | public function query(array $criteria, $limit, $offset) |
|
| 84 | |||
| 85 | /** |
||
| 86 | * {@inheritdoc} |
||
| 87 | */ |
||
| 88 | public function properties() |
||
| 92 | |||
| 93 | /** |
||
| 94 | * {@inheritdoc} |
||
| 95 | */ |
||
| 96 | public function size() |
||
| 100 | |||
| 101 | /** |
||
| 102 | * Paginates the given collection of data. |
||
| 103 | * |
||
| 104 | * @param array $data The collection data |
||
| 105 | * @param int $limit Logs per page |
||
| 106 | * @param int $offset The number of the page |
||
| 107 | * |
||
| 108 | * @return array |
||
| 109 | */ |
||
| 110 | private function paginate($data, $limit, $offset) |
||
| 114 | |||
| 115 | /** |
||
| 116 | * Compares the given two items. |
||
| 117 | * |
||
| 118 | * @param mixed $item1 The first item |
||
| 119 | * @param mixed $item2 The second item |
||
| 120 | * |
||
| 121 | * @return int |
||
| 122 | */ |
||
| 123 | View Code Duplication | private function sort($item1, $item2) |
|
| 141 | } |
||
| 142 |
This check looks for
@paramannotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive.
Most often this is a case of a parameter that can be null in addition to its declared types.