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 |
||
8 | class MailDefinitionParserXml implements ParserInterface |
||
9 | { |
||
10 | /** |
||
11 | * @var XsdValidator |
||
12 | */ |
||
13 | private $validator; |
||
14 | |||
15 | /** |
||
16 | * @var string |
||
17 | */ |
||
18 | private $xsdFile; |
||
19 | |||
20 | /** |
||
21 | * @param XsdValidator $validator |
||
22 | * @param $xsdFile |
||
23 | */ |
||
24 | public function __construct(XsdValidator $validator, $xsdFile) |
||
29 | |||
30 | /** |
||
31 | * Parse XML Mail Definition string |
||
32 | * |
||
33 | * which looks something like this |
||
34 | * <code> |
||
35 | * <email> |
||
36 | * <to name="yourname">[email protected]</email> |
||
37 | * <subject locale="de">Your subject</subject> |
||
38 | * <messageText locale="de">Your Message</messageText> |
||
39 | * </email> |
||
40 | * </code> |
||
41 | * |
||
42 | * @param string $xml |
||
43 | * @param string $locale |
||
44 | * |
||
45 | * @return ParsedMessage |
||
46 | * |
||
47 | * @throws \Exception |
||
48 | */ |
||
49 | public function parseMailDefinition($xml, $locale = null) |
||
84 | |||
85 | /** |
||
86 | * @param \SimpleXMLElement $element |
||
87 | * @param string $locale |
||
88 | * |
||
89 | * @return string |
||
90 | * |
||
91 | * @throws \Exception |
||
92 | */ |
||
93 | protected function getLocalizedTagContent(\SimpleXMLElement $element, $locale = null) |
||
112 | |||
113 | /** |
||
114 | * @param string $string |
||
115 | * @param bool $removeThatShit |
||
116 | * |
||
117 | * @return mixed |
||
118 | */ |
||
119 | protected function multilineRemoveIndent($string, $removeThatShit = false) |
||
127 | } |
||
128 |
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.