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 | ||
| 16 | class HookManagerTest extends TestCase { | ||
| 17 | |||
| 18 | /** | ||
| 19 | * The hook manager we're testing. | ||
| 20 | * | ||
| 21 | * @var Hook_Manager | ||
| 22 | */ | ||
| 23 | private $hook_manager; | ||
| 24 | |||
| 25 | /** | ||
| 26 | * Setup runs before each test. | ||
| 27 | * | ||
| 28 | * @before | ||
| 29 | */ | ||
| 30 | 	public function set_up() { | ||
| 33 | |||
| 34 | /** | ||
| 35 | * Teardown runs after each test. | ||
| 36 | * | ||
| 37 | * @after | ||
| 38 | */ | ||
| 39 | 	public function tear_down() { | ||
| 42 | |||
| 43 | /** | ||
| 44 | * Tests that the hook manager can add actions. | ||
| 45 | */ | ||
| 46 | View Code Duplication | 	public function test_adds_action() { | |
| 54 | |||
| 55 | /** | ||
| 56 | * Tests that the hook manager can add filters. | ||
| 57 | */ | ||
| 58 | View Code Duplication | 	public function test_adds_filters() { | |
| 66 | |||
| 67 | /** | ||
| 68 | * Tests that the hook manager removes hooks on reset. | ||
| 69 | */ | ||
| 70 | 	public function test_resets() { | ||
| 81 | } | ||
| 82 |