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 |
||
9 | class Test_Terms_Of_Service extends TestCase { |
||
10 | |||
11 | /** |
||
12 | * Test setup. |
||
13 | */ |
||
14 | public function setUp() { |
||
19 | |||
20 | /** |
||
21 | * Test teardown. |
||
22 | */ |
||
23 | public function tearDown() { |
||
26 | |||
27 | /** |
||
28 | * @covers Automattic\Jetpack\Terms_Of_Service->agree |
||
29 | */ |
||
30 | public function test_agree() { |
||
36 | |||
37 | /** |
||
38 | * @covers Automattic\Jetpack\Terms_Of_Service->revoke |
||
39 | */ |
||
40 | public function test_revoke() { |
||
46 | |||
47 | /** |
||
48 | * @covers Automattic\Jetpack\Terms_Of_Service->has_agreed |
||
49 | */ |
||
50 | public function test_has_agreed_before_the_site_agrees() { |
||
54 | |||
55 | /** |
||
56 | * @covers Automattic\Jetpack\Terms_Of_Service->has_agreed |
||
57 | */ |
||
58 | public function test_has_agreed_is_development_mode() { |
||
64 | |||
65 | /** |
||
66 | * @covers Automattic\Jetpack\Terms_Of_Service->has_agreed |
||
67 | */ |
||
68 | View Code Duplication | public function test_has_agreed_is_active_mode() { |
|
78 | |||
79 | /** |
||
80 | * @covers Automattic\Jetpack\Terms_Of_Service->has_agreed |
||
81 | */ |
||
82 | View Code Duplication | public function test_has_agreed_is_not_active_mode() { |
|
92 | |||
93 | /** |
||
94 | * Mock a global function and make it return a certain value. |
||
95 | * |
||
96 | * @param string $function_name Name of the function. |
||
97 | * @param mixed $return_value Return value of the function. |
||
98 | * @return phpmock\Mock The mock object. |
||
99 | */ |
||
100 | protected function mock_function( $function_name, $return_value = null, $called_with = null ) { |
||
112 | } |
||
113 |