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 |
||
5 | class CheckboxTest extends FormTestCase { |
||
6 | |||
7 | /** @test */ |
||
8 | public function it_can_be_rendered() |
||
14 | |||
15 | /** @test */ |
||
16 | public function it_is_unchecked_by_default() |
||
22 | |||
23 | /** @test */ |
||
24 | public function it_can_be_checked() |
||
30 | |||
31 | /** @test */ |
||
32 | View Code Duplication | public function it_renders_model_values() |
|
39 | |||
40 | /** @test */ |
||
41 | public function it_can_fill_model_values() |
||
51 | |||
52 | /** @test */ |
||
53 | public function it_can_be_unchecked() |
||
59 | |||
60 | /** @test */ |
||
61 | public function it_provides_expected_values() |
||
68 | |||
69 | /** @test */ |
||
70 | public function it_provides_expected_default_values() |
||
77 | |||
78 | /** @test */ |
||
79 | public function it_validates_required() |
||
87 | |||
88 | } |
||
89 |
If you implement
__call
and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.This is often the case, when
__call
is implemented by a parent class and only the child class knows which methods exist: