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 ManagerTest extends TestCase { |
||
10 | public function setUp() { |
||
15 | |||
16 | public function tearDown() { |
||
20 | |||
21 | function test_class_implements_interface() { |
||
25 | |||
26 | /** |
||
27 | * @covers Automattic\Jetpack\Connection\Manager::is_active |
||
28 | */ |
||
29 | public function test_is_active_when_connected() { |
||
40 | |||
41 | /** |
||
42 | * @covers Automattic\Jetpack\Connection\Manager::is_active |
||
43 | */ |
||
44 | public function test_is_active_when_not_connected() { |
||
51 | |||
52 | /** |
||
53 | * @covers Automattic\Jetpack\Connection\Manager::is_user_connected |
||
54 | */ |
||
55 | public function test_is_user_connected_with_default_user_id_logged_out() { |
||
60 | |||
61 | /** |
||
62 | * @covers Automattic\Jetpack\Connection\Manager::is_user_connected |
||
63 | */ |
||
64 | public function test_is_user_connected_with_false_user_id_logged_out() { |
||
69 | |||
70 | /** |
||
71 | * @covers Automattic\Jetpack\Connection\Manager::is_user_connected |
||
72 | */ |
||
73 | public function test_is_user_connected_with_user_id_logged_out_not_connected() { |
||
81 | |||
82 | /** |
||
83 | * @covers Automattic\Jetpack\Connection\Manager::is_user_connected |
||
84 | */ |
||
85 | View Code Duplication | public function test_is_user_connected_with_default_user_id_logged_in() { |
|
97 | |||
98 | /** |
||
99 | * @covers Automattic\Jetpack\Connection\Manager::is_user_connected |
||
100 | */ |
||
101 | View Code Duplication | public function test_is_user_connected_with_user_id_logged_in() { |
|
113 | |||
114 | /** |
||
115 | * Mock a global function and make it return a certain value. |
||
116 | * |
||
117 | * @param string $function_name Name of the function. |
||
118 | * @param mixed $return_value Return value of the function. |
||
119 | * @return phpmock\Mock The mock object. |
||
120 | */ |
||
121 | protected function mock_function( $function_name, $return_value = null ) { |
||
130 | } |
||
131 |