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 |
||
| 19 | class LoadingGeneratedManifestsTest extends TestCase { |
||
| 20 | |||
| 21 | /** |
||
| 22 | * The path to the test manifest we want to operate on. |
||
| 23 | */ |
||
| 24 | const TEST_MANIFEST_PATH = 'vendor/composer/test-manifest.php'; |
||
| 25 | |||
| 26 | /** |
||
| 27 | * The manifest handler we're testing. |
||
| 28 | * |
||
| 29 | * @var Manifest_Reader |
||
| 30 | */ |
||
| 31 | private $manifest_handler; |
||
| 32 | |||
| 33 | /** |
||
| 34 | * Setup runs before each test. |
||
| 35 | * |
||
| 36 | * @before |
||
| 37 | */ |
||
| 38 | public function set_up() { |
||
| 41 | |||
| 42 | /** |
||
| 43 | * Teardown runs after each test. |
||
| 44 | * |
||
| 45 | * @after |
||
| 46 | */ |
||
| 47 | public function tear_down() { |
||
| 50 | |||
| 51 | /** |
||
| 52 | * Tests that the classmap manifest we generate can be read by the handler. |
||
| 53 | */ |
||
| 54 | View Code Duplication | public function test_that_handler_reads_classmap_manifests() { |
|
| 82 | |||
| 83 | /** |
||
| 84 | * Tests that the PSR-4 manifest we generate can be read by the handler. |
||
| 85 | */ |
||
| 86 | View Code Duplication | public function test_that_handler_reads_psr4_manifests() { |
|
| 114 | |||
| 115 | /** |
||
| 116 | * Tests that the files manifest we generate can be read by the handler. |
||
| 117 | */ |
||
| 118 | View Code Duplication | public function test_that_handler_reads_files_manifests() { |
|
| 146 | |||
| 147 | /** |
||
| 148 | * Writes the test manifest for the tests to use. |
||
| 149 | * |
||
| 150 | * @param string $autoload_type The type of manifest to generate. |
||
| 151 | * @param array $content The content to write a manifest using. |
||
| 152 | */ |
||
| 153 | private function write_test_manifest( $autoload_type, $content ) { |
||
| 159 | } |
||
| 160 |