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 Test_Status extends TestCase { |
||
11 | /** |
||
12 | * Default site URL. |
||
13 | * |
||
14 | * @var string |
||
15 | */ |
||
16 | private $site_url = 'https://yourjetpack.blog'; |
||
17 | |||
18 | /** |
||
19 | * Test setup. |
||
20 | */ |
||
21 | public function setUp() { |
||
24 | |||
25 | /** |
||
26 | * Test teardown. |
||
27 | */ |
||
28 | public function tearDown() { |
||
31 | |||
32 | /** |
||
33 | * @covers Automattic\Jetpack\Status::is_development_mode |
||
34 | */ |
||
35 | View Code Duplication | public function test_is_development_mode_default() { |
|
46 | |||
47 | /** |
||
48 | * @covers Automattic\Jetpack\Status::is_development_mode |
||
49 | */ |
||
50 | View Code Duplication | public function test_is_development_mode_filter_true() { |
|
60 | |||
61 | /** |
||
62 | * @covers Automattic\Jetpack\Status::is_development_mode |
||
63 | */ |
||
64 | View Code Duplication | public function test_is_development_mode_filter_bool() { |
|
74 | |||
75 | /** |
||
76 | * @covers Automattic\Jetpack\Status::is_development_mode |
||
77 | */ |
||
78 | View Code Duplication | public function test_is_development_mode_localhost() { |
|
90 | |||
91 | /** |
||
92 | * @covers Automattic\Jetpack\Status::is_development_mode |
||
93 | * |
||
94 | * @runInSeparateProcess |
||
95 | */ |
||
96 | public function test_is_development_mode_constant() { |
||
113 | |||
114 | /** |
||
115 | * @covers Automattic\Jetpack\Status::is_multi_network |
||
116 | */ |
||
117 | public function test_is_multi_network_not_multisite() { |
||
122 | |||
123 | /** |
||
124 | * @covers Automattic\Jetpack\Status::is_multi_network |
||
125 | */ |
||
126 | public function test_is_multi_network_when_single_network() { |
||
134 | |||
135 | /** |
||
136 | * @covers Automattic\Jetpack\Status::is_multi_network |
||
137 | */ |
||
138 | public function test_is_multi_network_when_multiple_networks() { |
||
146 | |||
147 | /** |
||
148 | * Mock a global function with particular arguments and make it return a certain value. |
||
149 | * |
||
150 | * @param string $function_name Name of the function. |
||
151 | * @param array $args Array of argument sets, last value of each set is used as a return value. |
||
152 | * @return phpmock\Mock The mock object. |
||
153 | */ |
||
154 | protected function mock_function_with_args( $function_name, $args = array() ) { |
||
175 | |||
176 | /** |
||
177 | * Mock a set of filters. |
||
178 | * |
||
179 | * @param array $args Array of filters with their arguments. |
||
|
|||
180 | * @return phpmock\Mock The mock object. |
||
181 | */ |
||
182 | protected function mock_filters( $filters = array() ) { |
||
185 | |||
186 | /** |
||
187 | * Mock a set of constants. |
||
188 | * |
||
189 | * @param array $args Array of sets with constants and their respective values. |
||
190 | * @return phpmock\Mock The mock object. |
||
191 | */ |
||
192 | protected function mock_constants( $constants = array() ) { |
||
202 | |||
203 | /** |
||
204 | * Mock a global function and make it return a certain value. |
||
205 | * |
||
206 | * @param string $function_name Name of the function. |
||
207 | * @param mixed $return_value Return value of the function. |
||
208 | * @return phpmock\Mock The mock object. |
||
209 | */ |
||
210 | View Code Duplication | protected function mock_function( $function_name, $return_value = null ) { |
|
219 | |||
220 | /** |
||
221 | * Mock $wpdb->get_var() and make it return a certain value. |
||
222 | * |
||
223 | * @param mixed $return_value Return value of the function. |
||
224 | * @return PHPUnit\Framework\MockObject\MockObject The mock object. |
||
225 | */ |
||
226 | protected function mock_wpdb_get_var( $return_value = null ) { |
||
235 | |||
236 | /** |
||
237 | * Clean up the existing $wpdb->get_var() mock. |
||
238 | */ |
||
239 | protected function clean_mock_wpdb_get_var() { |
||
243 | } |
||
244 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.