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 |
||
17 | abstract class XmlUtil |
||
18 | { |
||
19 | /** |
||
20 | * Ищет среди потомков элемента $parent, первый элемент с именем тега $childName |
||
21 | * |
||
22 | * @param DOMElement $parent |
||
23 | * @param string $childName |
||
24 | * |
||
25 | * @return DOMElement|null |
||
26 | */ |
||
27 | 112 | public static function getChildElement(DOMElement $parent, $childName) |
|
41 | |||
42 | /** |
||
43 | * Ищет среди потомков элемента $parent, первый элемент с именем тега $childName. В случае если элемент не найден, |
||
44 | * бросается исключение |
||
45 | * |
||
46 | * @param DOMElement $parent |
||
47 | * @param string $childName |
||
48 | * |
||
49 | * @return DOMElement |
||
50 | */ |
||
51 | 5 | public static function getRequiredChildElement(DOMElement $parent, $childName) |
|
64 | |||
65 | |||
66 | |||
67 | /** |
||
68 | * Ищет среди потомков элемента $parent, элементы с именем тега $childName |
||
69 | * |
||
70 | * @param DOMElement $parent |
||
71 | * @param string $childName |
||
72 | * |
||
73 | * @return DOMElement[]|null |
||
74 | */ |
||
75 | 124 | public static function getChildElements(DOMElement $parent, $childName) |
|
96 | |||
97 | /** |
||
98 | * Ищет среди потомков элемента $parent, первый элемент с именем тега $childName и возвращает его текст |
||
99 | * |
||
100 | * @param DOMElement $parent |
||
101 | * @param string $childName |
||
102 | * |
||
103 | * @return null |
||
104 | */ |
||
105 | 2 | public static function getChildText(DOMElement $parent, $childName) |
|
115 | |||
116 | /** |
||
117 | * Получает текст из нод потомков |
||
118 | * |
||
119 | * @param DOMElement $node |
||
120 | * @return string |
||
121 | */ |
||
122 | 67 | public static function getText(DOMElement $node) |
|
138 | |||
139 | /** |
||
140 | * @param DOMElement $node |
||
141 | * @param string $attributeName |
||
142 | * |
||
143 | * @return string |
||
144 | */ |
||
145 | 134 | public static function getRequiredAttributeValue(DOMElement $node, $attributeName) |
|
162 | |||
163 | |||
164 | /** |
||
165 | * @fixme Реализовать методу \OldTown\Workflow\Loader\XmlUtil::encode |
||
166 | * |
||
167 | * @param string $string |
||
168 | * @return string |
||
169 | */ |
||
170 | 20 | public static function encode($string) |
|
174 | } |
||
175 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.