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 NotificationParser |
||
14 | { |
||
15 | /** |
||
16 | * Regex-search-rule. |
||
17 | */ |
||
18 | const RULE = '/\{([a-zA-Z0-9_\.]+)\}/m'; |
||
19 | |||
20 | /** |
||
21 | * Parse a notification and return the body text. |
||
22 | * |
||
23 | * @param ModelNotification $notification |
||
24 | * @return string |
||
25 | * @throws ExtraParamsException |
||
26 | */ |
||
27 | public function parse($notification) |
||
54 | |||
55 | /** |
||
56 | * Get an array of all placehodlers. |
||
57 | * |
||
58 | * @param string $body |
||
59 | * @return array |
||
60 | */ |
||
61 | protected function getValues($body) |
||
68 | |||
69 | /** |
||
70 | * Replace a single placeholder. |
||
71 | * |
||
72 | * @param string $body |
||
73 | * @param string $valueMatch |
||
74 | * @param string $replacer |
||
75 | * @return string |
||
76 | */ |
||
77 | protected function replace($body, $valueMatch, $replacer) |
||
83 | |||
84 | /** |
||
85 | * @param array|object $object |
||
86 | * @param string $key |
||
87 | * @param null|mixed $default |
||
88 | * @return mixed |
||
89 | */ |
||
90 | protected function mixedGet($object, $key, $default = null) |
||
118 | } |
||
119 |
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.
If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.