We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
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 |
||
| 18 | class Paginator |
||
| 19 | { |
||
| 20 | const MODE_REGULAR = false; |
||
| 21 | const MODE_PROMISE = true; |
||
| 22 | |||
| 23 | /** |
||
| 24 | * @var callable |
||
| 25 | */ |
||
| 26 | private $fetcher; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * @var bool |
||
| 30 | */ |
||
| 31 | private $promise; |
||
| 32 | |||
| 33 | /** |
||
| 34 | * @var int |
||
| 35 | */ |
||
| 36 | private $totalCount; |
||
| 37 | |||
| 38 | /** |
||
| 39 | * @param callable $fetcher |
||
| 40 | * @param bool $promise |
||
| 41 | */ |
||
| 42 | 14 | public function __construct(callable $fetcher, $promise = self::MODE_REGULAR) |
|
| 47 | |||
| 48 | /** |
||
| 49 | * @param Argument|array $args |
||
| 50 | * @param int|callable $total |
||
| 51 | * @param array $callableArgs |
||
| 52 | * |
||
| 53 | * @return Connection|object A connection or a promise |
||
| 54 | */ |
||
| 55 | 7 | public function backward($args, $total, array $callableArgs = []) |
|
| 72 | |||
| 73 | /** |
||
| 74 | * @param Argument|array $args |
||
| 75 | * |
||
| 76 | * @return Connection|object A connection or a promise |
||
| 77 | */ |
||
| 78 | 7 | public function forward($args) |
|
| 102 | |||
| 103 | /** |
||
| 104 | * @param Argument|array $args |
||
| 105 | * @param int|callable $total |
||
| 106 | * @param array $callableArgs |
||
| 107 | * |
||
| 108 | * @return Connection|object A connection or a promise |
||
| 109 | */ |
||
| 110 | 5 | public function auto($args, $total, $callableArgs = []) |
|
| 132 | |||
| 133 | /** |
||
| 134 | * @param array|object $entities An array of entities to paginate or a promise |
||
| 135 | * @param callable $callback |
||
| 136 | * |
||
| 137 | * @return Connection|object A connection or a promise |
||
| 138 | */ |
||
| 139 | 14 | private function handleEntities($entities, callable $callback) |
|
| 147 | |||
| 148 | /** |
||
| 149 | * @param Argument|array $args |
||
| 150 | * |
||
| 151 | * @return Argument |
||
| 152 | */ |
||
| 153 | 14 | private function protectArgs($args) |
|
| 157 | |||
| 158 | /** |
||
| 159 | * @param int $total |
||
| 160 | * @param array $callableArgs |
||
| 161 | * |
||
| 162 | * @return int|mixed |
||
| 163 | */ |
||
| 164 | 8 | private function computeTotalCount($total, array $callableArgs = []) |
|
| 174 | } |
||
| 175 |
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.