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 |
||
13 | class FilterResponseTest extends TestCase |
||
14 | { |
||
15 | /** |
||
16 | * @test |
||
17 | * @covers ::__construct |
||
18 | */ |
||
19 | public function construct() |
||
33 | |||
34 | /** |
||
35 | * @test |
||
36 | * @covers ::__construct |
||
37 | */ |
||
38 | public function constructWithErrors() |
||
52 | |||
53 | /** |
||
54 | * @test |
||
55 | * @covers ::__construct |
||
56 | */ |
||
57 | public function constructDefault() |
||
69 | |||
70 | /** |
||
71 | * @test |
||
72 | * @covers ::__construct |
||
73 | */ |
||
74 | public function gettingInvalidPropertyThrowsException() |
||
82 | |||
83 | /** |
||
84 | * @test |
||
85 | * @covers ::__construct |
||
86 | */ |
||
87 | View Code Duplication | public function settingValidPropertyThrowsAnException() |
|
95 | |||
96 | /** |
||
97 | * @test |
||
98 | * @covers ::__construct |
||
99 | */ |
||
100 | View Code Duplication | public function settingInvalidPropertyThrowsAnException() |
|
108 | |||
109 | /** |
||
110 | * @test |
||
111 | * @covers ::toArray |
||
112 | * @dataProvider provideToArray |
||
113 | * |
||
114 | * @param array $value The filtered value to pass to the response. |
||
115 | * @param array $errors The errors to pass to the response. |
||
116 | * @param array $unknowns The unknowns to pass to the response. |
||
117 | * @param array $expected The expected array value. |
||
118 | */ |
||
119 | public function toArray(array $value, array $errors, array $unknowns, array $expected) |
||
126 | |||
127 | /** |
||
128 | * @return array |
||
129 | */ |
||
130 | public function provideToArray() : array |
||
147 | } |
||
148 |
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@property
annotation 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.