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 |
||
9 | class Paginator |
||
10 | { |
||
11 | const MODE_REGULAR = false; |
||
12 | const MODE_PROMISE = true; |
||
13 | |||
14 | /** @var callable */ |
||
15 | private $fetcher; |
||
16 | |||
17 | /** @var bool */ |
||
18 | private $promise; |
||
19 | |||
20 | /** @var int */ |
||
21 | private $totalCount; |
||
22 | |||
23 | /** |
||
24 | * @param callable $fetcher |
||
25 | * @param bool $promise |
||
26 | */ |
||
27 | 14 | public function __construct(callable $fetcher, $promise = self::MODE_REGULAR) |
|
32 | |||
33 | /** |
||
34 | * @param Argument $args |
||
35 | * @param int|callable $total |
||
36 | * @param array $callableArgs |
||
37 | * |
||
38 | * @return Connection|object A connection or a promise |
||
39 | */ |
||
40 | 7 | public function backward($args, $total, array $callableArgs = []) |
|
57 | |||
58 | /** |
||
59 | * @param Argument $args |
||
60 | * |
||
61 | * @return Connection|object A connection or a promise |
||
62 | */ |
||
63 | 7 | public function forward($args) |
|
87 | |||
88 | /** |
||
89 | * @param Argument $args |
||
90 | * @param int|callable $total |
||
91 | * @param array $callableArgs |
||
92 | * |
||
93 | * @return Connection|object A connection or a promise |
||
94 | */ |
||
95 | 5 | public function auto($args, $total, $callableArgs = []) |
|
117 | |||
118 | /** |
||
119 | * @param array|object $entities An array of entities to paginate or a promise |
||
120 | * @param callable $callback |
||
121 | * |
||
122 | * @return Connection|object A connection or a promise |
||
123 | */ |
||
124 | 14 | private function handleEntities($entities, callable $callback) |
|
132 | |||
133 | /** |
||
134 | * @param Argument|array $args |
||
135 | * |
||
136 | * @return Argument |
||
137 | */ |
||
138 | 14 | private function protectArgs($args) |
|
142 | |||
143 | /** |
||
144 | * @param int $total |
||
145 | * @param array $callableArgs |
||
146 | * |
||
147 | * @return int|mixed |
||
148 | */ |
||
149 | 8 | private function computeTotalCount($total, array $callableArgs = []) |
|
159 | } |
||
160 |
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.