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 |
||
| 12 | class YamlStorage implements Storage |
||
| 13 | { |
||
| 14 | /** |
||
| 15 | * The data collection. |
||
| 16 | * |
||
| 17 | * @var array |
||
| 18 | */ |
||
| 19 | private $data; |
||
| 20 | |||
| 21 | /** |
||
| 22 | * Constructor. |
||
| 23 | * |
||
| 24 | * @param string $yamlFile The dir path of YAML file |
||
|
|
|||
| 25 | */ |
||
| 26 | public function __construct($yamlFile = null) |
||
| 36 | |||
| 37 | /** |
||
| 38 | * {@inheritdoc} |
||
| 39 | */ |
||
| 40 | View Code Duplication | public function findAll($limit, $offset) |
|
| 53 | |||
| 54 | /** |
||
| 55 | * {@inheritdoc} |
||
| 56 | */ |
||
| 57 | View Code Duplication | public function query(array $criteria, $limit, $offset) |
|
| 75 | |||
| 76 | /** |
||
| 77 | * {@inheritdoc} |
||
| 78 | */ |
||
| 79 | public function properties() |
||
| 83 | |||
| 84 | /** |
||
| 85 | * {@inheritdoc} |
||
| 86 | */ |
||
| 87 | public function size() |
||
| 91 | |||
| 92 | /** |
||
| 93 | * Paginates the given collection of data. |
||
| 94 | * |
||
| 95 | * @param array $data The collection data |
||
| 96 | * @param int $limit Logs per page |
||
| 97 | * @param int $offset The number of the page |
||
| 98 | * |
||
| 99 | * @return array |
||
| 100 | */ |
||
| 101 | private function paginate($data, $limit, $offset) |
||
| 105 | |||
| 106 | /** |
||
| 107 | * Compares the given two items. |
||
| 108 | * |
||
| 109 | * @param mixed $item1 The first item |
||
| 110 | * @param mixed $item2 The second item |
||
| 111 | * |
||
| 112 | * @return int |
||
| 113 | */ |
||
| 114 | View Code Duplication | private function sort($item1, $item2) |
|
| 132 | } |
||
| 133 |
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.