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 |
||
| 9 | class FieldMapSpec extends ObjectBehavior |
||
| 10 | { |
||
| 11 | function let(FieldNode $f1, FieldNode $f2) |
||
| 18 | |||
| 19 | function it_returns_field_via_field_method(FieldNode $f1) |
||
| 23 | |||
| 24 | function it_throws_if_field_is_not_found() |
||
| 29 | |||
| 30 | function it_returns_field_via_magic_method(FieldNode $f1) |
||
| 34 | |||
| 35 | function it_does_not_match_if_critera_includes_unknown_field() |
||
| 39 | |||
| 40 | View Code Duplication | function it_does_match_if_all_criteria_fields_match(FieldNode $f1, FieldNode $f2) |
|
| 50 | |||
| 51 | View Code Duplication | function it_does_not_match_if_any_criteria_fields_fail_to_match(FieldNode $f1, FieldNode $f2) |
|
| 61 | } |
||
| 62 |
Since your code implements the magic getter
_get, this function will be called for any read access on an undefined variable. You can add the@propertyannotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.