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 |
||
| 17 | class Promise implements HttpPromise |
||
| 18 | { |
||
| 19 | /** |
||
| 20 | * Promise status. |
||
| 21 | * |
||
| 22 | * @var string |
||
| 23 | */ |
||
| 24 | private $state = HttpPromise::PENDING; |
||
| 25 | |||
| 26 | /** |
||
| 27 | * PSR7 received response. |
||
| 28 | * |
||
| 29 | * @var ResponseInterface |
||
| 30 | */ |
||
| 31 | private $response; |
||
| 32 | |||
| 33 | /** |
||
| 34 | * Execution error. |
||
| 35 | * |
||
| 36 | * @var Exception |
||
| 37 | */ |
||
| 38 | private $exception; |
||
| 39 | |||
| 40 | /** |
||
| 41 | * @var callable|null |
||
| 42 | */ |
||
| 43 | private $onFulfilled; |
||
| 44 | |||
| 45 | /** |
||
| 46 | * @var callable|null |
||
| 47 | */ |
||
| 48 | private $onRejected; |
||
| 49 | |||
| 50 | /** |
||
| 51 | * React Event Loop used for synchronous processing. |
||
| 52 | * |
||
| 53 | * @var LoopInterface |
||
| 54 | */ |
||
| 55 | private $loop; |
||
| 56 | |||
| 57 | 109 | public function __construct(LoopInterface $loop) |
|
| 61 | |||
| 62 | /** |
||
| 63 | * Allow to apply callable when the promise resolve. |
||
| 64 | * |
||
| 65 | * @param callable|null $onFulfilled |
||
| 66 | * @param callable|null $onRejected |
||
| 67 | * |
||
| 68 | * @return Promise |
||
| 69 | */ |
||
| 70 | 56 | public function then(callable $onFulfilled = null, callable $onRejected = null) |
|
| 100 | |||
| 101 | /** |
||
| 102 | * Resolve this promise |
||
| 103 | * |
||
| 104 | * @param ResponseInterface $response |
||
| 105 | * |
||
| 106 | * @internal |
||
| 107 | */ |
||
| 108 | 106 | View Code Duplication | public function resolve(ResponseInterface $response) |
| 122 | |||
| 123 | /** |
||
| 124 | * Reject this promise |
||
| 125 | * |
||
| 126 | * @param Exception $exception |
||
| 127 | * |
||
| 128 | * @internal |
||
| 129 | */ |
||
| 130 | 3 | View Code Duplication | public function reject(Exception $exception) |
| 144 | |||
| 145 | /** |
||
| 146 | * {@inheritdoc} |
||
| 147 | */ |
||
| 148 | 109 | public function getState() |
|
| 152 | |||
| 153 | /** |
||
| 154 | * {@inheritdoc} |
||
| 155 | */ |
||
| 156 | 109 | public function wait($unwrap = true) |
|
| 170 | } |
||
| 171 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.