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 EmailTest extends FormTestCase { |
||
6 | |||
7 | /** @test */ |
||
8 | public function it_can_be_rendered() |
||
14 | |||
15 | /** @test */ |
||
16 | public function it_renders_a_default_value() |
||
22 | |||
23 | /** @test */ |
||
24 | View Code Duplication | public function it_renders_model_values() |
|
31 | |||
32 | /** @test */ |
||
33 | View Code Duplication | public function it_can_fill_model_values() |
|
43 | |||
44 | /** @test */ |
||
45 | public function it_escapes_value() |
||
51 | |||
52 | /** @test */ |
||
53 | public function it_provides_expected_values() |
||
60 | |||
61 | /** @test */ |
||
62 | public function it_provides_expected_default_values() |
||
69 | |||
70 | /** @test */ |
||
71 | public function it_validates_required() |
||
77 | |||
78 | /** @test */ |
||
79 | public function it_validates_email() |
||
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: