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 |
||
| 3 | class CalendarEntry extends DataObject |
||
| 4 | { |
||
| 5 | |||
| 6 | public static $db = array( |
||
| 7 | "Title" => "Text", |
||
| 8 | "Date" => "Date", |
||
| 9 | "Time" => "Text", |
||
| 10 | "Description" => "Text" |
||
| 11 | ); |
||
| 12 | |||
| 13 | public static $has_one = array( |
||
| 14 | "CalendarPage" => "CalendarPage", |
||
| 15 | "Image" => "Image" |
||
| 16 | ); |
||
| 17 | |||
| 18 | public static $summary_fields = array( |
||
| 19 | "Date" => "Date", |
||
| 20 | "Title" => "Title" |
||
| 21 | ); |
||
| 22 | |||
| 23 | public static $default_sort = "Date ASC, Time ASC"; |
||
| 24 | |||
| 25 | public function validate() |
||
| 36 | |||
| 37 | public function getCMSFields() |
||
| 65 | |||
| 66 | public function getMonthDigit() |
||
| 72 | |||
| 73 | public function Link() |
||
| 77 | |||
| 78 | public function getYear() |
||
| 84 | |||
| 85 | View Code Duplication | public function canCreate($members = null) |
|
| 94 | |||
| 95 | View Code Duplication | public function canEdit($members = null) |
|
| 104 | |||
| 105 | View Code Duplication | public function canDelete($members = null) |
|
| 114 | |||
| 115 | View Code Duplication | public function canView($members = null) |
|
| 124 | } |
||
| 125 |
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.