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 |
||
| 9 | class PagerPersister implements PagerPersisterInterface |
||
| 10 | { |
||
| 11 | /** |
||
| 12 | * @var Indexable |
||
| 13 | */ |
||
| 14 | private $indexable; |
||
| 15 | |||
| 16 | /** |
||
| 17 | * @param Indexable $indexable |
||
| 18 | */ |
||
| 19 | public function __construct(Indexable $indexable) |
||
| 23 | |||
| 24 | /** |
||
| 25 | * {@inheritdoc} |
||
| 26 | */ |
||
| 27 | public function insert(Pagerfanta $pager, ObjectPersisterInterface $objectPersister, \Closure $loggerClosure = null, array $options = array()) |
||
| 66 | |||
| 67 | /** |
||
| 68 | * Filters objects away if they are not indexable. |
||
| 69 | * |
||
| 70 | * @param array $options |
||
| 71 | * @param array $objects |
||
| 72 | * @return array |
||
| 73 | */ |
||
| 74 | View Code Duplication | protected function filterObjects(array $options, array $objects) |
|
| 94 | } |
||
| 95 |
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.