Conditions | 10 |
Paths | 8 |
Total Lines | 30 |
Code Lines | 13 |
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 |
||
43 | public function insert($content):PrototypeElement{ |
||
44 | |||
45 | if(!is_array($content)){ |
||
46 | |||
47 | foreach($this->ownerDocument->toNodeList($content) as $node){ |
||
48 | $this->insert_bottom($node); |
||
49 | } |
||
50 | |||
51 | return $this; |
||
52 | } |
||
53 | |||
54 | foreach(['before', 'after', 'top', 'bottom'] as $pos){ |
||
55 | |||
56 | if(!array_key_exists($pos, $content)){ |
||
57 | continue; |
||
58 | } |
||
59 | |||
60 | $nodes = $this->ownerDocument->toNodeList($content[$pos]); |
||
61 | |||
62 | if($pos === 'top' && $this->hasChildNodes() || $pos === 'after' && $this->nextSibling){ |
||
63 | $nodes->reverse(); |
||
64 | } |
||
65 | |||
66 | foreach($nodes as $node){ |
||
67 | call_user_func_array([$this, 'insert_'.$pos], [$node]); |
||
68 | } |
||
69 | |||
70 | } |
||
71 | |||
72 | return $this; |
||
73 | } |
||
121 |