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 |
||
| 18 | class ManifestReaderTest extends TestCase { |
||
| 19 | |||
| 20 | /** |
||
| 21 | * The older version of the autoloader that we want to use. Note that |
||
| 22 | * the version should support PSR-4 since this one does. |
||
| 23 | */ |
||
| 24 | const OLDER_VERSION = '2.4.0.0'; |
||
| 25 | |||
| 26 | /** |
||
| 27 | * The directory of a plugin using the autoloader. |
||
| 28 | * |
||
| 29 | * @var string |
||
| 30 | */ |
||
| 31 | private static $older_plugin_dir; |
||
| 32 | |||
| 33 | /** |
||
| 34 | * The manifest reader we're testing. |
||
| 35 | * |
||
| 36 | * @var Manifest_Reader |
||
| 37 | */ |
||
| 38 | private $reader; |
||
| 39 | |||
| 40 | /** |
||
| 41 | * Setup before class runs before the class. |
||
| 42 | * |
||
| 43 | * @beforeClass |
||
| 44 | */ |
||
| 45 | public static function set_up_before_class() { |
||
| 48 | |||
| 49 | /** |
||
| 50 | * Setup runs before each test. |
||
| 51 | * |
||
| 52 | * @before |
||
| 53 | */ |
||
| 54 | public function set_up() { |
||
| 57 | |||
| 58 | /** |
||
| 59 | * Tests that nothing is read without any plugins. |
||
| 60 | */ |
||
| 61 | public function test_reads_nothing_without_plugins() { |
||
| 72 | |||
| 73 | /** |
||
| 74 | * Tests that nothing is read for plugins that have no manifest. |
||
| 75 | */ |
||
| 76 | public function test_reads_nothing_for_plugins_without_manifests() { |
||
| 87 | |||
| 88 | /** |
||
| 89 | * Tests that a single plugin manifest can be read successfully. |
||
| 90 | */ |
||
| 91 | View Code Duplication | public function test_reads_single_plugin_manifest() { |
|
| 104 | |||
| 105 | /** |
||
| 106 | * Tests that the reader only keeps the latest version when processing multiple manifests. |
||
| 107 | */ |
||
| 108 | View Code Duplication | public function test_read_overwrites_older_version_in_manifest() { |
|
| 121 | |||
| 122 | /** |
||
| 123 | * Tests that the reader ignores older versions when a newer version is already set. |
||
| 124 | */ |
||
| 125 | View Code Duplication | public function test_read_ignores_older_version_when_newer_already_loaded() { |
|
| 138 | } |
||
| 139 |