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 |
||
14 | class WP_Test_Autoloader extends TestCase { |
||
15 | |||
16 | /** |
||
17 | * Setup runs before each test. |
||
18 | */ |
||
19 | public function setup() { |
||
24 | |||
25 | /** |
||
26 | * Tests whether enqueueing adds a class to the global array. |
||
27 | */ |
||
28 | View Code Duplication | public function test_enqueueing_adds_to_the_global_array() { |
|
36 | |||
37 | /** |
||
38 | * Tests whether enqueueing adds the latest class version to the global array. |
||
39 | */ |
||
40 | View Code Duplication | public function test_enqueueing_adds_the_latest_version_to_the_global_array() { |
|
50 | |||
51 | /** |
||
52 | * Tests whether enqueueing prioritizes the stable version of the class when the |
||
53 | * JETPACK_AUTOLOAD_DEV constant is not set. This test must be run before |
||
54 | * 'test_enqueueing_adds_the_dev_version_to_the_global_array' because that test |
||
55 | * sets JETPACK_AUTOLOAD_DEV. |
||
56 | */ |
||
57 | public function test_enqueueing_does_not_add_the_dev_version_to_the_global_array() { |
||
68 | |||
69 | /** |
||
70 | * Tests whether enqueueing prioritizes the dev version of the class when the |
||
71 | * JETPACK_AUTOLOAD_DEV constant is set to true. |
||
72 | * |
||
73 | * @runInSeparateProcess |
||
74 | * @preserveGlobalState disabled |
||
75 | */ |
||
76 | View Code Duplication | public function test_enqueueing_adds_the_dev_version_to_the_global_array() { |
|
88 | |||
89 | /** |
||
90 | * Tests whether enqueueing works with autoloading. |
||
91 | */ |
||
92 | public function test_enqueue_class_to_autoload_works_as_expected() { |
||
99 | } |
||
100 |