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 |
||
| 10 | class PromiseCancelled implements PromiseInterface |
||
| 11 | { |
||
| 12 | /** |
||
| 13 | * @var Error|Exception|string|null |
||
| 14 | */ |
||
| 15 | protected $reason; |
||
| 16 | |||
| 17 | /** |
||
| 18 | * @param Error|Exception|string|null $reason |
||
| 19 | * @throws InvalidArgumentException |
||
| 20 | */ |
||
| 21 | 140 | public function __construct($reason = null) |
|
| 32 | |||
| 33 | /** |
||
| 34 | * |
||
| 35 | */ |
||
| 36 | 134 | public function __destruct() |
|
| 40 | |||
| 41 | /** |
||
| 42 | * @override |
||
| 43 | * @inheritDoc |
||
| 44 | */ |
||
| 45 | 82 | public function then(callable $onFulfilled = null, callable $onRejected = null, callable $onCancel = null) |
|
| 71 | |||
| 72 | /** |
||
| 73 | * @override |
||
| 74 | * @inheritDoc |
||
| 75 | */ |
||
| 76 | 65 | View Code Duplication | public function done(callable $onFulfilled = null, callable $onRejected = null, callable $onCancel = null) |
| 95 | |||
| 96 | /** |
||
| 97 | * @override |
||
| 98 | * @inheritDoc |
||
| 99 | */ |
||
| 100 | 2 | public function spread(callable $onFulfilled = null, callable $onRejected = null, callable $onCancel = null) |
|
| 110 | |||
| 111 | /** |
||
| 112 | * @override |
||
| 113 | * @inheritDoc |
||
| 114 | */ |
||
| 115 | 1 | public function success(callable $onSuccess) |
|
| 119 | |||
| 120 | /** |
||
| 121 | * @override |
||
| 122 | * @inheritDoc |
||
| 123 | */ |
||
| 124 | 1 | public function failure(callable $onFailure) |
|
| 128 | |||
| 129 | /** |
||
| 130 | * @override |
||
| 131 | * @inheritDoc |
||
| 132 | */ |
||
| 133 | 1 | public function abort(callable $onCancel) |
|
| 137 | |||
| 138 | /** |
||
| 139 | * @override |
||
| 140 | * @inheritDoc |
||
| 141 | */ |
||
| 142 | 5 | View Code Duplication | public function always(callable $onFulfilledOrRejected) |
| 154 | |||
| 155 | /** |
||
| 156 | * @override |
||
| 157 | * @inheritDoc |
||
| 158 | */ |
||
| 159 | 1 | public function isPending() |
|
| 163 | |||
| 164 | /** |
||
| 165 | * @override |
||
| 166 | * @inheritDoc |
||
| 167 | */ |
||
| 168 | 3 | public function isFulfilled() |
|
| 172 | |||
| 173 | /** |
||
| 174 | * @override |
||
| 175 | * @inheritDoc |
||
| 176 | */ |
||
| 177 | 3 | public function isRejected() |
|
| 181 | |||
| 182 | /** |
||
| 183 | * @override |
||
| 184 | * @inheritDoc |
||
| 185 | */ |
||
| 186 | 5 | public function isCancelled() |
|
| 190 | |||
| 191 | /** |
||
| 192 | * @override |
||
| 193 | * @inheritDoc |
||
| 194 | */ |
||
| 195 | public function getPromise() |
||
| 199 | |||
| 200 | /** |
||
| 201 | * @override |
||
| 202 | * @inheritDoc |
||
| 203 | */ |
||
| 204 | 1 | public function resolve($value = null) |
|
| 208 | |||
| 209 | /** |
||
| 210 | * @override |
||
| 211 | * @inheritDoc |
||
| 212 | */ |
||
| 213 | 1 | public function reject($reason = null) |
|
| 217 | |||
| 218 | /** |
||
| 219 | * @override |
||
| 220 | * @inheritDoc |
||
| 221 | */ |
||
| 222 | 1 | public function cancel($reason = null) |
|
| 226 | |||
| 227 | /** |
||
| 228 | * @see Promise::getValue |
||
| 229 | */ |
||
| 230 | protected function getValue() |
||
| 234 | |||
| 235 | /** |
||
| 236 | * @see Promise::getReason |
||
| 237 | */ |
||
| 238 | 112 | protected function getReason() |
|
| 242 | |||
| 243 | /** |
||
| 244 | * @param Error|Exception|string $reason |
||
| 245 | * @throws Error|Exception |
||
| 246 | */ |
||
| 247 | 17 | protected function throwError($reason) |
|
| 256 | } |
||
| 257 |