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 |
||
16 | class ShutdownHandlerTest extends TestCase { |
||
17 | |||
18 | /** |
||
19 | * The mock Plugins_Handler instance. |
||
20 | * |
||
21 | * @var Plugins_Handler|\PHPUnit\Framework\MockObject\MockObject |
||
22 | */ |
||
23 | private $plugins_handler; |
||
24 | |||
25 | /** |
||
26 | * Setup runs before each test. |
||
27 | * |
||
28 | * @before |
||
29 | */ |
||
30 | public function set_up() { |
||
35 | |||
36 | /** |
||
37 | * Tests that the shutdown handler caches the active plugins. |
||
38 | */ |
||
39 | View Code Duplication | public function test_shutdown_caches_active_plugins() { |
|
54 | |||
55 | /** |
||
56 | * Tests that the shutdown handler does not update the cache if it has not changed. |
||
57 | */ |
||
58 | View Code Duplication | public function test_shutdown_does_not_save_unchanged_cache() { |
|
72 | |||
73 | /** |
||
74 | * Tests that shutting down early empties the cache. |
||
75 | */ |
||
76 | public function test_shutdown_early_empties_cache() { |
||
86 | |||
87 | /** |
||
88 | * Tests that expected exceptions thrown during shutdown aren't propogated. |
||
89 | */ |
||
90 | View Code Duplication | public function test_shutdown_handles_exceptions() { |
|
105 | } |
||
106 |