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 |
||
| 10 | { |
||
| 11 | /** |
||
| 12 | * @var ObjectPersisterInterface |
||
| 13 | */ |
||
| 14 | private $objectPersister; |
||
| 15 | |||
| 16 | /** |
||
| 17 | * @var Indexable |
||
| 18 | */ |
||
| 19 | private $indexable; |
||
| 20 | |||
| 21 | /** |
||
| 22 | * PagerPersister constructor. |
||
| 23 | * @param ObjectPersisterInterface $objectPersister |
||
| 24 | * @param Indexable $indexable |
||
| 25 | */ |
||
| 26 | public function __construct(ObjectPersisterInterface $objectPersister, Indexable $indexable) |
||
| 31 | |||
| 32 | public function insert(Pagerfanta $pager, \Closure $loggerClosure = null, array $options = array()) |
||
| 73 | |||
| 74 | /** |
||
| 75 | * Filters objects away if they are not indexable. |
||
| 76 | * |
||
| 77 | * @param array $options |
||
| 78 | * @param array $objects |
||
| 79 | * @return array |
||
| 80 | */ |
||
| 81 | View Code Duplication | protected function filterObjects(array $options, array $objects) |
|
| 101 | } |
||
| 102 |
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.