Conditions | 32 |
Paths | 10384 |
Total Lines | 129 |
Code Lines | 76 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
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 |
||
196 | protected function addParagraphs(DOMElement $el) { |
||
197 | // no need to call recursively, just queue up |
||
198 | $elsToProcess = array($el); |
||
199 | $inlinesToProcess = array(); |
||
200 | while ($el = array_shift($elsToProcess)) { |
||
201 | // if true, we can alter all child nodes, if not, we'll just call |
||
202 | // addParagraphs on each element in the descendInto list |
||
203 | $alterInline = in_array($el->nodeName, $this->_alterList); |
||
204 | |||
205 | // inside affected elements, we want to trim leading whitespace from |
||
206 | // the first text node |
||
207 | $ltrimFirstTextNode = true; |
||
208 | |||
209 | // should we open a new AUTOP element to move inline elements into? |
||
210 | $openP = true; |
||
211 | $autop = null; |
||
212 | |||
213 | // after BR, ignore a newline |
||
214 | $isFollowingBr = false; |
||
215 | |||
216 | $node = $el->firstChild; |
||
217 | while (null !== $node) { |
||
218 | if ($alterInline) { |
||
219 | if ($openP) { |
||
220 | $openP = false; |
||
221 | // create a P to move inline content into (this may be removed later) |
||
222 | $autop = $el->insertBefore($this->_doc->createElement('autop'), $node); |
||
223 | } |
||
224 | } |
||
225 | |||
226 | $isElement = ($node->nodeType === XML_ELEMENT_NODE); |
||
227 | if ($isElement) { |
||
228 | $isBlock = in_array($node->nodeName, $this->_blocks); |
||
229 | if (!$isBlock) { |
||
230 | // if we start with an inline element we don't need to do this |
||
231 | $ltrimFirstTextNode = false; |
||
232 | } |
||
233 | } else { |
||
234 | $isBlock = false; |
||
235 | } |
||
236 | |||
237 | if ($alterInline) { |
||
238 | $isText = ($node->nodeType === XML_TEXT_NODE); |
||
239 | $isLastInline = (! $node->nextSibling |
||
240 | || ($node->nextSibling->nodeType === XML_ELEMENT_NODE |
||
241 | && in_array($node->nextSibling->nodeName, $this->_blocks))); |
||
242 | if ($isElement) { |
||
243 | $isFollowingBr = ($node->nodeName === 'br'); |
||
244 | } |
||
245 | |||
246 | if ($isText) { |
||
247 | $nodeText = $node->nodeValue; |
||
248 | |||
249 | if ($ltrimFirstTextNode) { |
||
250 | // we're at the beginning of a sequence of text/inline elements |
||
251 | $nodeText = ltrim($nodeText); |
||
252 | $ltrimFirstTextNode = false; |
||
253 | } |
||
254 | if ($isFollowingBr && preg_match('@^[ \\t]*\\n[ \\t]*@', $nodeText, $m)) { |
||
255 | // if a user ends a line with <br>, don't add a second BR |
||
256 | $nodeText = substr($nodeText, strlen($m[0])); |
||
257 | } |
||
258 | if ($isLastInline) { |
||
259 | // we're at the end of a sequence of text/inline elements |
||
260 | $nodeText = rtrim($nodeText); |
||
261 | } |
||
262 | $nodeText = str_replace("\n", $this->_unique . 'NL', $nodeText); |
||
263 | $tmpNode = $node; |
||
264 | $node = $node->nextSibling; // move loop to next node |
||
265 | |||
266 | // alter node in place, then move into AUTOP |
||
267 | $tmpNode->nodeValue = $nodeText; |
||
268 | $autop->appendChild($tmpNode); |
||
269 | |||
270 | continue; |
||
271 | } |
||
272 | } |
||
273 | if ($isBlock || ! $node->nextSibling) { |
||
274 | if ($isBlock) { |
||
275 | if (in_array($node->nodeName, $this->_descendList)) { |
||
276 | $elsToProcess[] = $node; |
||
277 | //$this->addParagraphs($node); |
||
278 | } |
||
279 | } |
||
280 | $openP = true; |
||
281 | $ltrimFirstTextNode = true; |
||
282 | } |
||
283 | if ($alterInline) { |
||
284 | if (! $isBlock) { |
||
285 | $tmpNode = $node; |
||
286 | if ($isElement && false !== strpos($tmpNode->textContent, "\n")) { |
||
287 | $inlinesToProcess[] = $tmpNode; |
||
288 | } |
||
289 | $node = $node->nextSibling; |
||
290 | $autop->appendChild($tmpNode); |
||
291 | continue; |
||
292 | } |
||
293 | } |
||
294 | |||
295 | $node = $node->nextSibling; |
||
296 | } |
||
297 | } |
||
298 | |||
299 | // handle inline nodes |
||
300 | // no need to recurse, just queue up |
||
301 | while ($el = array_shift($inlinesToProcess)) { |
||
302 | $ignoreLeadingNewline = false; |
||
303 | foreach ($el->childNodes as $node) { |
||
304 | if ($node->nodeType === XML_ELEMENT_NODE) { |
||
305 | if ($node->nodeValue === 'BR') { |
||
306 | $ignoreLeadingNewline = true; |
||
307 | } else { |
||
308 | $ignoreLeadingNewline = false; |
||
309 | if (false !== strpos($node->textContent, "\n")) { |
||
310 | $inlinesToProcess[] = $node; |
||
311 | } |
||
312 | } |
||
313 | continue; |
||
314 | } elseif ($node->nodeType === XML_TEXT_NODE) { |
||
315 | $text = $node->nodeValue; |
||
316 | if ($text[0] === "\n" && $ignoreLeadingNewline) { |
||
317 | $text = substr($text, 1); |
||
318 | $ignoreLeadingNewline = false; |
||
319 | } |
||
320 | $node->nodeValue = str_replace("\n", $this->_unique . 'BR', $text); |
||
321 | } |
||
322 | } |
||
323 | } |
||
324 | } |
||
325 | } |
||
326 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..