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.InvalidClassFileName |
||
| 13 | class Test_Hook_Manager extends TestCase { |
||
| 14 | |||
| 15 | /** |
||
| 16 | * The hook manager we're testing. |
||
| 17 | * |
||
| 18 | * @var Hook_Manager |
||
| 19 | */ |
||
| 20 | private $hook_manager; |
||
| 21 | |||
| 22 | /** |
||
| 23 | * Setup runs before each test. |
||
| 24 | * |
||
| 25 | * @before |
||
| 26 | */ |
||
| 27 | public function set_up() { |
||
| 28 | $this->hook_manager = new Hook_Manager(); |
||
| 29 | } |
||
| 30 | |||
| 31 | /** |
||
| 32 | * Teardown runs after each test. |
||
| 33 | * |
||
| 34 | * @after |
||
| 35 | */ |
||
| 36 | public function tear_down() { |
||
| 37 | cleanup_test_wordpress_data(); |
||
| 38 | } |
||
| 39 | |||
| 40 | /** |
||
| 41 | * Tests that the hook manager can add actions. |
||
| 42 | */ |
||
| 43 | View Code Duplication | public function test_adds_action() { |
|
| 51 | |||
| 52 | /** |
||
| 53 | * Tests that the hook manager can add filters. |
||
| 54 | */ |
||
| 55 | View Code Duplication | public function test_adds_filters() { |
|
| 63 | |||
| 64 | /** |
||
| 65 | * Tests that the hook manager removes hooks on reset. |
||
| 66 | */ |
||
| 67 | public function test_resets() { |
||
| 78 | } |
||
| 79 |