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 |
||
19 | class PromiseDeferred extends AbstractPromise implements DeferredInterface |
||
20 | { |
||
21 | /** |
||
22 | * @var DeferredInterface[] |
||
23 | */ |
||
24 | private $deferreds = array(); |
||
25 | |||
26 | /** |
||
27 | * @var PromiseInterface |
||
28 | */ |
||
29 | private $actual = null; |
||
30 | |||
31 | /** |
||
32 | * @param callable $onFulfilled |
||
33 | * @param callable $onRejected |
||
34 | * @param callable $onNotify |
||
35 | * |
||
36 | * @return PromiseInterface |
||
37 | */ |
||
38 | public function then(callable $onFulfilled = null, callable $onRejected = null, callable $onNotify = null) |
||
46 | |||
47 | /** |
||
48 | * {@inheritdoc} |
||
49 | */ |
||
50 | View Code Duplication | public function resolve($value = null) |
|
64 | |||
65 | /** |
||
66 | * {@inheritdoc} |
||
67 | */ |
||
68 | View Code Duplication | public function reject($reason = null) |
|
81 | |||
82 | /** |
||
83 | * {@inheritdoc} |
||
84 | */ |
||
85 | public function notify($state = null) |
||
95 | |||
96 | /** |
||
97 | * {@inheritdoc} |
||
98 | */ |
||
99 | public function state() |
||
103 | |||
104 | /** |
||
105 | * {@inheritdoc} |
||
106 | */ |
||
107 | public function promise() |
||
111 | |||
112 | /** |
||
113 | * @param callable $onFulfilled |
||
114 | * @param callable $onRejected |
||
115 | * @param callable $onNotify |
||
116 | * |
||
117 | * @return \Cubiche\Core\Async\Promise\DeferredProxy |
||
118 | */ |
||
119 | private function enqueue(callable $onFulfilled = null, callable $onRejected = null, callable $onNotify = null) |
||
126 | } |
||
127 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.