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 TestCase extends \WP_UnitTestCase { |
||
11 | |||
12 | /** |
||
13 | * @param $class |
||
14 | * @param $property |
||
15 | * @return mixed |
||
16 | */ |
||
17 | public function getReflectionPropertyValue( $class, $property ) |
||
23 | |||
24 | /** |
||
25 | * @param $class |
||
26 | * @param $property |
||
27 | * @param $value |
||
28 | */ |
||
29 | public function setReflectionPropertyValue( $class, $property, $value ) |
||
35 | |||
36 | /** |
||
37 | * @param $class |
||
38 | * @param $method |
||
39 | * @return mixed |
||
40 | */ |
||
41 | View Code Duplication | public function reflectionMethodInvoke( $class, $method ) |
|
50 | |||
51 | /** |
||
52 | * @param $class |
||
53 | * @param $method |
||
54 | * @param $args |
||
55 | * @return mixed |
||
56 | */ |
||
57 | View Code Duplication | public function reflectionMethodInvokeArgs( $class, $method, $args ) |
|
66 | |||
67 | /** |
||
68 | * @return string |
||
69 | */ |
||
70 | protected function get_sample_response() { |
||
75 | |||
76 | /** |
||
77 | * @return Mock |
||
78 | */ |
||
79 | protected function getMockGeocoder() { |
||
89 | |||
90 | /** |
||
91 | * @return Mock |
||
92 | */ |
||
93 | protected function getMockLocation() { |
||
119 | } |
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.