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 PathProcessorTest extends TestCase { |
||
17 | |||
18 | /** |
||
19 | * The path processor we're testing. |
||
20 | * |
||
21 | * @var Path_Processor |
||
22 | */ |
||
23 | private $processor; |
||
24 | |||
25 | /** |
||
26 | * Setup runs before each test. |
||
27 | * |
||
28 | * @before |
||
29 | */ |
||
30 | public function set_up() { |
||
36 | |||
37 | /** |
||
38 | * Teardown runs after each test. |
||
39 | * |
||
40 | * @after |
||
41 | */ |
||
42 | public function tear_down() { |
||
46 | |||
47 | /** |
||
48 | * Tests that the processor is able to successfully tokenize and untokenize paths. |
||
49 | */ |
||
50 | View Code Duplication | public function test_handles_path_tokenization_and_untokenization() { |
|
59 | |||
60 | /** |
||
61 | * Tests that the processor is able to successfully tokenize and untokenize paths on Windows. |
||
62 | */ |
||
63 | View Code Duplication | public function test_handles_path_tokenization_and_untokenization_with_windows_paths() { |
|
72 | |||
73 | /** |
||
74 | * Tests that the processor resolves symlinks when untokenizing. |
||
75 | */ |
||
76 | public function test_path_untokenization_resolves_symlinks() { |
||
81 | |||
82 | /** |
||
83 | * Tests that find_directory_with_autoloader does not work on non-PHP files. |
||
84 | */ |
||
85 | public function test_does_not_find_directory_for_non_php_files() { |
||
93 | |||
94 | /** |
||
95 | * Tests that find_directory_with_autoloader does not work for files that don't have the autoloader. |
||
96 | */ |
||
97 | public function test_does_not_find_directory_for_not_autoloaded_plugin() { |
||
105 | |||
106 | /** |
||
107 | * Tests that find_directory_with_autoloader finds directories for plugins that have the autoloader. |
||
108 | */ |
||
109 | public function test_finds_directory_for_autoloaded_plugin() { |
||
117 | |||
118 | /** |
||
119 | * Tests that find_directory_with_autoloader finds directories using Windows paths. |
||
120 | */ |
||
121 | public function test_finds_directory_for_autoloaded_plugin_with_windows_paths() { |
||
129 | |||
130 | /** |
||
131 | * Tests that find_directory_with_autoloader finds the realpath of directories that use symlinks. |
||
132 | */ |
||
133 | public function test_finds_directory_realpath_for_symlinked_plugin() { |
||
141 | } |
||
142 |
If you suppress an error, we recommend checking for the error condition explicitly: