Conditions | 14 |
Paths | 135 |
Total Lines | 76 |
Code Lines | 38 |
Lines | 0 |
Ratio | 0 % |
Changes | 3 | ||
Bugs | 0 | Features | 1 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
124 | protected function handleNode(\DOMNode & $node, &$path = array()) |
||
125 | { |
||
126 | // Collect normal HTML DOM nodes |
||
127 | /** @var \DOMNode[] $children */ |
||
128 | $children = array(); |
||
129 | foreach ($node->childNodes as $child) { |
||
130 | // Work only with DOMElements |
||
131 | if ($child->nodeType == 1) { |
||
132 | $children[] = $child; |
||
133 | } |
||
134 | } |
||
135 | // Group current level HTML DOM nodes by tag name and count them |
||
136 | $childrenTagArray = array(); |
||
137 | foreach ($children as $child) { |
||
138 | $tag = $child->nodeName; |
||
139 | if (!isset($childrenTagArray[$tag])) { |
||
140 | $childrenTagArray[$tag] = 1; |
||
141 | } else $childrenTagArray[$tag]++; |
||
142 | } |
||
143 | // Iterate all normal DOM nodes |
||
144 | foreach ($children as $child) { |
||
145 | // Create LESS node |
||
146 | $childNode = new HTMLDOMNode($child); |
||
147 | // If this LESS node has NO CSS classes |
||
148 | if (sizeof($childNode->class) == 0) { |
||
149 | // Create new multidimensional array key group |
||
150 | if (!isset($path[$child->nodeName])) { |
||
151 | $path[$child->nodeName] = array(); |
||
152 | } |
||
153 | // Go deeper in recursion with current child node and new path |
||
154 | $this->handleNode($child, $path[$child->nodeName]); |
||
155 | } else { // This child DOM node has CSS classes |
||
156 | // Get first node class and remove it from array og classes |
||
157 | $firstClass = array_shift($childNode->class); |
||
158 | // Save current LESS path |
||
159 | $oldPath = &$path; |
||
160 | // If there is more than one DOM child node with this tag name at this level |
||
161 | if ($childrenTagArray[$childNode->tag] > 1 && $childNode->tag != 'div') { |
||
162 | // Create correct LESS class name |
||
163 | $class = '&.' . $firstClass; |
||
164 | // Create new multidimensional array key group with tag name group |
||
165 | if (!isset($path[$child->nodeName][$class])) { |
||
166 | $path[$child->nodeName][$class] = array(); |
||
167 | } |
||
168 | // Go deeper in recursion with current child node and new path with tag name group and CSS class name group |
||
169 | $this->handleNode($child, $path[$child->nodeName][$class]); |
||
170 | // Make new path as current |
||
171 | $path = &$path[$child->nodeName][$class]; |
||
172 | } else { // There is only on child with this tag name at this level |
||
173 | // Create correct LESS class name |
||
174 | $class = '.' . $firstClass; |
||
175 | // Create new multidimensional array key group without tag name group |
||
176 | if (!isset($path[$class])) { |
||
177 | $path[$class] = array(); |
||
178 | } |
||
179 | // Go deeper in recursion with current child node and new path with CSS class name group |
||
180 | $this->handleNode($child, $path[$class]); |
||
181 | // Make new path as current |
||
182 | $path = &$path[$class]; |
||
183 | } |
||
184 | // Iterate all other classes starting from second class |
||
185 | foreach ($childNode->class as $class) { |
||
186 | // Create correct LESS class name |
||
187 | $class = '&.' . $class; |
||
188 | // Create new multidimensional array key group with tag name group |
||
189 | if (!isset($path[$class])) { |
||
190 | $path[$class] = array(); |
||
191 | } |
||
192 | // Go deeper in recursion with current child node and new path with tag name group and CSS class name group |
||
193 | $this->handleNode($child, $path[$class]); |
||
194 | } |
||
195 | // Return old LESS path tree |
||
196 | $path = &$oldPath; |
||
197 | } |
||
198 | } |
||
199 | } |
||
200 | } |
||
201 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: