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 Test_Loading_Generated_Manifests extends TestCase { |
||
17 | |||
18 | /** |
||
19 | * The path to the test manifest we want to operate on. |
||
20 | */ |
||
21 | const TEST_MANIFEST_PATH = TEST_DATA_PATH . '/plugins/dummy_current/test-manifest.php'; |
||
22 | |||
23 | /** |
||
24 | * The manifest handler we're testing. |
||
25 | * |
||
26 | * @var Manifest_Reader |
||
27 | */ |
||
28 | private $manifest_handler; |
||
29 | |||
30 | /** |
||
31 | * Setup runs before each test. |
||
32 | * |
||
33 | * @before |
||
34 | */ |
||
35 | public function set_up() { |
||
36 | $this->manifest_handler = new Manifest_Reader( new Version_Selector() ); |
||
37 | |||
38 | // Make sure the test manifest does not exist. |
||
39 | if ( file_exists( self::TEST_MANIFEST_PATH ) ) { |
||
40 | unlink( self::TEST_MANIFEST_PATH ); |
||
41 | } |
||
42 | } |
||
43 | |||
44 | /** |
||
45 | * Teardown runs after each test. |
||
46 | * |
||
47 | * @after |
||
48 | */ |
||
49 | public function tear_down() { |
||
50 | // Make sure the test manifest does not exist. |
||
51 | if ( file_exists( self::TEST_MANIFEST_PATH ) ) { |
||
52 | unlink( self::TEST_MANIFEST_PATH ); |
||
53 | } |
||
54 | } |
||
55 | |||
56 | /** |
||
57 | * Tests that the classmap manifest we generate can be read by the handler. |
||
58 | */ |
||
59 | View Code Duplication | public function test_that_handler_reads_classmap_manifests() { |
|
87 | |||
88 | /** |
||
89 | * Tests that the PSR-4 manifest we generate can be read by the handler. |
||
90 | */ |
||
91 | View Code Duplication | public function test_that_handler_reads_psr4_manifests() { |
|
119 | |||
120 | /** |
||
121 | * Tests that the files manifest we generate can be read by the handler. |
||
122 | */ |
||
123 | View Code Duplication | public function test_that_handler_reads_files_manifests() { |
|
151 | |||
152 | /** |
||
153 | * Writes the test manifest for the tests to use. |
||
154 | * |
||
155 | * @param string $autoload_type The type of manifest to generate. |
||
156 | * @param array $content The content to write a manifest using. |
||
157 | */ |
||
158 | private function write_test_manifest( $autoload_type, $content ) { |
||
164 | } |
||
165 |