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 Membership extends PopoloObject |
||
6 | { |
||
7 | protected $properties = [ |
||
8 | 'role', |
||
9 | 'personId', |
||
10 | 'person', |
||
11 | 'organizationId', |
||
12 | 'organization', |
||
13 | 'areaId', |
||
14 | 'area', |
||
15 | 'legislativePeriodId', |
||
16 | 'legislativePeriod', |
||
17 | 'onBehalfOfId', |
||
18 | 'onBehalfOf', |
||
19 | 'postId', |
||
20 | 'post', |
||
21 | 'startDate', |
||
22 | 'endDate', |
||
23 | 'current', |
||
24 | ]; |
||
25 | |||
26 | 3 | public function __toString() |
|
30 | |||
31 | 3 | protected function getRole() |
|
35 | |||
36 | 12 | protected function getPersonId() |
|
40 | |||
41 | 3 | protected function getPerson() |
|
45 | |||
46 | 9 | protected function getOrganizationId() |
|
50 | |||
51 | 3 | protected function getOrganization() |
|
55 | |||
56 | 6 | protected function getAreaId() |
|
60 | |||
61 | 3 | protected function getArea() |
|
65 | |||
66 | 6 | protected function getLegislativePeriodId() |
|
70 | |||
71 | 3 | protected function getLegislativePeriod() |
|
75 | |||
76 | 6 | protected function getOnBehalfOfId() |
|
80 | |||
81 | 3 | protected function getOnBehalfOf() |
|
85 | |||
86 | 6 | protected function getPostId() |
|
90 | |||
91 | 3 | protected function getPost() |
|
95 | |||
96 | 12 | protected function getStartDate() |
|
101 | |||
102 | 6 | protected function getEndDate() |
|
107 | |||
108 | 54 | protected function getKeyForHash() |
|
114 | |||
115 | protected function getCurrent() |
||
119 | |||
120 | 9 | public function currentAt($when) |
|
124 | |||
125 | 9 | View Code Duplication | public function equals($other) |
132 | } |
||
133 |
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.