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 // phpcs:ignore WordPress.Files.FileName |
||
17 | class LatestAutoloaderGuardTest extends TestCase { |
||
18 | |||
19 | /** |
||
20 | * The mock Plugins_Handler instance. |
||
21 | * |
||
22 | * @var Plugins_Handler|\PHPUnit\Framework\MockObject\MockObject |
||
23 | */ |
||
24 | private $plugins_handler; |
||
25 | |||
26 | /** |
||
27 | * The mock Autoloader_Handler instance. |
||
28 | * |
||
29 | * @var Autoloader_Handler|\PHPUnit\Framework\MockObject\MockObject |
||
30 | */ |
||
31 | private $autoloader_handler; |
||
32 | |||
33 | /** |
||
34 | * The mock Autoloader_Locator instance. |
||
35 | * |
||
36 | * @var Autoloader_Locator|\PHPUnit\Framework\MockObject\MockObject |
||
37 | */ |
||
38 | private $autoloader_locator; |
||
39 | |||
40 | /** |
||
41 | * The class we're testing. |
||
42 | * |
||
43 | * @var Latest_Autoloader_Guard |
||
44 | */ |
||
45 | private $guard; |
||
46 | |||
47 | /** |
||
48 | * Setup runs before each test. |
||
49 | * |
||
50 | * @before |
||
51 | */ |
||
52 | public function set_up() { |
||
69 | |||
70 | /** |
||
71 | * Tests that the guard stops initialization when the autoloader has already initialized. |
||
72 | * |
||
73 | * @runInSeparateProcess |
||
74 | * @preserveGlobalState disabled |
||
75 | */ |
||
76 | View Code Duplication | public function test_should_stop_init_when_autoloader_already_initialized() { |
|
88 | |||
89 | /** |
||
90 | * Tests that the guard allows initialization when the autoloader has been initialized but we've been deliberately included by it. |
||
91 | * |
||
92 | * @preserveGlobalState disabled |
||
93 | */ |
||
94 | View Code Duplication | public function test_should_allow_init_when_including_latest() { |
|
107 | |||
108 | /** |
||
109 | * Tests that the guard stops initialization when not the latest autoloader. |
||
110 | * |
||
111 | * @preserveGlobalState disabled |
||
112 | */ |
||
113 | public function test_should_stop_init_when_not_latest_autoloader() { |
||
135 | |||
136 | /** |
||
137 | * Tests that the guard allows initialization when the latest. |
||
138 | */ |
||
139 | public function test_should_allow_init_when_latest() { |
||
154 | |||
155 | /** |
||
156 | * Tests that the guard resets when plugins have changed. |
||
157 | * |
||
158 | * @preserveGlobalState disabled |
||
159 | */ |
||
160 | public function test_should_stop_init_should_reset_when_plugins_change() { |
||
176 | } |
||
177 |