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 | * Mock a global function with particular arguments and make it return a certain value. |
||
| 116 | * |
||
| 117 | * @param string $function_name Name of the function. |
||
| 118 | * @param array $args Array of argument sets, last value of each set is used as a return value. |
||
| 119 | * @return phpmock\Mock The mock object. |
||
| 120 | */ |
||
| 121 | protected function mock_function_with_args( $function_name, $args = array() ) { |
||
| 142 | |||
| 143 | /** |
||
| 144 | * Mock a set of filters. |
||
| 145 | * |
||
| 146 | * @param array $args Array of filters with their arguments. |
||
|
|
|||
| 147 | * @return phpmock\Mock The mock object. |
||
| 148 | */ |
||
| 149 | protected function mock_filters( $filters = array() ) { |
||
| 152 | |||
| 153 | /** |
||
| 154 | * Mock a set of constants. |
||
| 155 | * |
||
| 156 | * @param array $args Array of sets with constants and their respective values. |
||
| 157 | * @return phpmock\Mock The mock object. |
||
| 158 | */ |
||
| 159 | protected function mock_constants( $constants = array() ) { |
||
| 169 | |||
| 170 | /** |
||
| 171 | * Mock a global function and make it return a certain value. |
||
| 172 | * |
||
| 173 | * @param string $function_name Name of the function. |
||
| 174 | * @param mixed $return_value Return value of the function. |
||
| 175 | * @return phpmock\Mock The mock object. |
||
| 176 | */ |
||
| 177 | View Code Duplication | protected function mock_function( $function_name, $return_value = null ) { |
|
| 186 | } |
||
| 187 |
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
$italyis not defined by the methodfinale(...).The most likely cause is that the parameter was removed, but the annotation was not.