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 |
||
| 13 | class Test_Path_Processor extends TestCase { |
||
| 14 | |||
| 15 | /** |
||
| 16 | * The path processor we're testing. |
||
| 17 | * |
||
| 18 | * @var Path_Processor |
||
| 19 | */ |
||
| 20 | private $processor; |
||
| 21 | |||
| 22 | /** |
||
| 23 | * Setup runs before each test. |
||
| 24 | * |
||
| 25 | * @before |
||
| 26 | */ |
||
| 27 | public function set_up() { |
||
| 33 | |||
| 34 | /** |
||
| 35 | * Teardown runs after each test. |
||
| 36 | * |
||
| 37 | * @after |
||
| 38 | */ |
||
| 39 | public function tear_down() { |
||
| 43 | |||
| 44 | /** |
||
| 45 | * Tests that the processor is able to successfully tokenize and untokenize paths. |
||
| 46 | */ |
||
| 47 | View Code Duplication | public function test_handles_path_tokenization_and_untokenization() { |
|
| 56 | |||
| 57 | /** |
||
| 58 | * Tests that the processor is able to successfully tokenize and untokenize paths on Windows. |
||
| 59 | */ |
||
| 60 | View Code Duplication | public function test_handles_path_tokenization_and_untokenization_with_windows_paths() { |
|
| 69 | |||
| 70 | /** |
||
| 71 | * Tests that the processor resolves symlinks when untokenizing. |
||
| 72 | */ |
||
| 73 | public function test_path_untokenization_resolves_symlinks() { |
||
| 78 | |||
| 79 | /** |
||
| 80 | * Tests that find_directory_with_autoloader does not work on non-PHP files. |
||
| 81 | */ |
||
| 82 | public function test_does_not_find_directory_for_non_php_files() { |
||
| 90 | |||
| 91 | /** |
||
| 92 | * Tests that find_directory_with_autoloader does not work for files that don't have the autoloader. |
||
| 93 | */ |
||
| 94 | public function test_does_not_find_directory_for_not_autoloaded_plugin() { |
||
| 102 | |||
| 103 | /** |
||
| 104 | * Tests that find_directory_with_autoloader finds directories for plugins that have the autoloader. |
||
| 105 | */ |
||
| 106 | View Code Duplication | public function test_finds_directory_for_autoloaded_plugin() { |
|
| 114 | |||
| 115 | /** |
||
| 116 | * Tests that find_directory_with_autoloader finds directories using Windows paths. |
||
| 117 | */ |
||
| 118 | View Code Duplication | public function test_finds_directory_for_autoloaded_plugin_with_windows_paths() { |
|
| 126 | |||
| 127 | /** |
||
| 128 | * Tests that find_directory_with_autoloader finds the realpath of directories that use symlinks. |
||
| 129 | */ |
||
| 130 | View Code Duplication | public function test_finds_directory_realpath_for_symlinked_plugin() { |
|
| 138 | } |
||
| 139 |
If you suppress an error, we recommend checking for the error condition explicitly: