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() { |
||
28 | $this->processor = new Path_Processor(); |
||
29 | } |
||
30 | |||
31 | /** |
||
32 | * Tests that the process is able to successfully tokenize and untokenize paths. |
||
33 | */ |
||
34 | View Code Duplication | public function test_handles_path_tokenization_and_untokenization() { |
|
43 | |||
44 | /** |
||
45 | * Tests that find_directory_with_autoloader is able to successfully tokenize and untokenize paths on Windows. |
||
46 | */ |
||
47 | View Code Duplication | public function test_handles_path_tokenization_and_untokenization_with_windows_paths() { |
|
56 | |||
57 | /** |
||
58 | * Tests that find_directory_with_autoloader does not work on non-PHP files. |
||
59 | */ |
||
60 | public function test_does_not_find_directory_for_non_php_files() { |
||
68 | |||
69 | /** |
||
70 | * Tests that find_directory_with_autoloader does not work for files that don't have the autoloader. |
||
71 | */ |
||
72 | public function test_does_not_find_directory_for_not_autoloaded_plugin() { |
||
80 | |||
81 | /** |
||
82 | * Tests that find_directory_with_autoloader finds directories for plugins that have the autoloader. |
||
83 | */ |
||
84 | View Code Duplication | public function test_finds_directory_for_autoloaded_plugin() { |
|
92 | |||
93 | /** |
||
94 | * Tests that find_directory_with_autoloader finds directories using Windows paths. |
||
95 | */ |
||
96 | View Code Duplication | public function test_finds_directory_for_autoloaded_plugin_with_windows_paths() { |
|
104 | } |
||
105 |