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 |
||
24 | class PromiseTests extends PromiseInterfaceTestCase |
||
25 | { |
||
26 | /** |
||
27 | * @var Delegate |
||
28 | */ |
||
29 | protected $resolve; |
||
30 | |||
31 | /** |
||
32 | * @var Delegate |
||
33 | */ |
||
34 | protected $reject; |
||
35 | |||
36 | /** |
||
37 | * @var Delegate |
||
38 | */ |
||
39 | protected $notify; |
||
40 | |||
41 | /** |
||
42 | * {@inheritdoc} |
||
43 | */ |
||
44 | protected function defaultConstructorArguments() |
||
58 | |||
59 | /** |
||
60 | * {@inheritdoc} |
||
61 | */ |
||
62 | protected function resolve($value = null) |
||
66 | |||
67 | /** |
||
68 | * {@inheritdoc} |
||
69 | */ |
||
70 | protected function reject($reason = null) |
||
74 | |||
75 | /** |
||
76 | * {@inheritdoc} |
||
77 | */ |
||
78 | protected function notify($state = null) |
||
82 | |||
83 | /** |
||
84 | * Test __construct. |
||
85 | */ |
||
86 | public function testConstruct() |
||
112 | |||
113 | /** |
||
114 | * Test notify. |
||
115 | */ |
||
116 | View Code Duplication | public function testNotify() |
|
133 | |||
134 | /** |
||
135 | * {@inheritdoc} |
||
136 | */ |
||
137 | View Code Duplication | protected function promiseDataProvider() |
|
153 | } |
||
154 |
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.