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 |
||
7 | class Membership extends PopoloObject |
||
8 | { |
||
9 | protected $properties = [ |
||
10 | 'role', |
||
11 | 'personId', |
||
12 | 'person', |
||
13 | 'organizationId', |
||
14 | 'organization', |
||
15 | 'areaId', |
||
16 | 'area', |
||
17 | 'legislativePeriodId', |
||
18 | 'legislativePeriod', |
||
19 | 'onBehalfOfId', |
||
20 | 'onBehalfOf', |
||
21 | 'postId', |
||
22 | 'post', |
||
23 | 'startDate', |
||
24 | 'endDate', |
||
25 | 'current', |
||
26 | ]; |
||
27 | |||
28 | /** |
||
29 | * String representation of {@link Membership} |
||
30 | * |
||
31 | * @return string |
||
32 | */ |
||
33 | 3 | public function __toString() |
|
37 | |||
38 | 3 | protected function getRole() |
|
42 | |||
43 | 12 | protected function getPersonId() |
|
47 | |||
48 | 3 | protected function getPerson() |
|
52 | |||
53 | 9 | protected function getOrganizationId() |
|
57 | |||
58 | 3 | protected function getOrganization() |
|
62 | |||
63 | 6 | protected function getAreaId() |
|
67 | |||
68 | 3 | protected function getArea() |
|
72 | |||
73 | 6 | protected function getLegislativePeriodId() |
|
77 | |||
78 | 3 | protected function getLegislativePeriod() |
|
82 | |||
83 | 6 | protected function getOnBehalfOfId() |
|
87 | |||
88 | 3 | protected function getOnBehalfOf() |
|
92 | |||
93 | 6 | protected function getPostId() |
|
97 | |||
98 | 3 | protected function getPost() |
|
102 | |||
103 | 12 | protected function getStartDate() |
|
108 | |||
109 | 6 | protected function getEndDate() |
|
114 | |||
115 | 54 | protected function getKeyForHash() |
|
121 | |||
122 | protected function getCurrent() |
||
126 | |||
127 | 9 | public function currentAt($when) |
|
131 | |||
132 | 9 | View Code Duplication | public function equals($other) |
140 | } |
||
141 |
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.