| Conditions | 8 |
| Paths | 14 |
| Total Lines | 91 |
| 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 |
||
| 105 | protected function listOpen($call) |
||
| 106 | { |
||
| 107 | $depth = $this->interpretSyntax($call[1][0], $listType); |
||
| 108 | $end = end($this->listStack); |
||
| 109 | $key = key($this->listStack); |
||
| 110 | |||
| 111 | // Not allowed to be shallower than initialDepth |
||
| 112 | if ($depth < $this->initialDepth) { |
||
| 113 | $depth = $this->initialDepth; |
||
| 114 | } |
||
| 115 | |||
| 116 | if ($depth == $end[1]) { |
||
| 117 | // Just another item in the list... |
||
| 118 | if ($listType == $end[0]) { |
||
| 119 | $this->listCalls[] = array('listcontent_close',array(),$call[2]); |
||
| 120 | $this->listCalls[] = array('listitem_close',array(),$call[2]); |
||
| 121 | $this->listCalls[] = array('listitem_open',array($depth-1),$call[2]); |
||
| 122 | $this->listCalls[] = array('listcontent_open',array(),$call[2]); |
||
| 123 | |||
| 124 | // new list item, update list stack's index into current listitem_open |
||
| 125 | $this->listStack[$key][2] = count($this->listCalls) - 2; |
||
| 126 | |||
| 127 | // Switched list type... |
||
| 128 | } else { |
||
| 129 | $this->listCalls[] = array('listcontent_close',array(),$call[2]); |
||
| 130 | $this->listCalls[] = array('listitem_close',array(),$call[2]); |
||
| 131 | $this->listCalls[] = array('list'.$end[0].'_close', array(), $call[2]); |
||
| 132 | $this->listCalls[] = array('list'.$listType.'_open', array(), $call[2]); |
||
| 133 | $this->listCalls[] = array('listitem_open', array($depth-1), $call[2]); |
||
| 134 | $this->listCalls[] = array('listcontent_open',array(),$call[2]); |
||
| 135 | |||
| 136 | array_pop($this->listStack); |
||
| 137 | $this->listStack[] = array($listType, $depth, count($this->listCalls) - 2); |
||
| 138 | } |
||
| 139 | } elseif ($depth > $end[1]) { // Getting deeper... |
||
| 140 | $this->listCalls[] = array('listcontent_close',array(),$call[2]); |
||
| 141 | $this->listCalls[] = array('list'.$listType.'_open', array(), $call[2]); |
||
| 142 | $this->listCalls[] = array('listitem_open', array($depth-1), $call[2]); |
||
| 143 | $this->listCalls[] = array('listcontent_open',array(),$call[2]); |
||
| 144 | |||
| 145 | // set the node/leaf state of this item's parent listitem_open to NODE |
||
| 146 | $this->listCalls[$this->listStack[$key][2]][1][1] = self::NODE; |
||
| 147 | |||
| 148 | $this->listStack[] = array($listType, $depth, count($this->listCalls) - 2); |
||
| 149 | } else { // Getting shallower ( $depth < $end[1] ) |
||
| 150 | $this->listCalls[] = array('listcontent_close',array(),$call[2]); |
||
| 151 | $this->listCalls[] = array('listitem_close',array(),$call[2]); |
||
| 152 | $this->listCalls[] = array('list'.$end[0].'_close',array(),$call[2]); |
||
| 153 | |||
| 154 | // Throw away the end - done |
||
| 155 | array_pop($this->listStack); |
||
| 156 | |||
| 157 | while (1) { |
||
| 158 | $end = end($this->listStack); |
||
| 159 | $key = key($this->listStack); |
||
| 160 | |||
| 161 | if ($end[1] <= $depth) { |
||
| 162 | // Normalize depths |
||
| 163 | $depth = $end[1]; |
||
| 164 | |||
| 165 | $this->listCalls[] = array('listitem_close',array(),$call[2]); |
||
| 166 | |||
| 167 | if ($end[0] == $listType) { |
||
| 168 | $this->listCalls[] = array('listitem_open',array($depth-1),$call[2]); |
||
| 169 | $this->listCalls[] = array('listcontent_open',array(),$call[2]); |
||
| 170 | |||
| 171 | // new list item, update list stack's index into current listitem_open |
||
| 172 | $this->listStack[$key][2] = count($this->listCalls) - 2; |
||
| 173 | } else { |
||
| 174 | // Switching list type... |
||
| 175 | $this->listCalls[] = array('list'.$end[0].'_close', array(), $call[2]); |
||
| 176 | $this->listCalls[] = array('list'.$listType.'_open', array(), $call[2]); |
||
| 177 | $this->listCalls[] = array('listitem_open', array($depth-1), $call[2]); |
||
| 178 | $this->listCalls[] = array('listcontent_open',array(),$call[2]); |
||
| 179 | |||
| 180 | array_pop($this->listStack); |
||
| 181 | $this->listStack[] = array($listType, $depth, count($this->listCalls) - 2); |
||
| 182 | } |
||
| 183 | |||
| 184 | break; |
||
| 185 | |||
| 186 | // Haven't dropped down far enough yet.... ( $end[1] > $depth ) |
||
| 187 | } else { |
||
| 188 | $this->listCalls[] = array('listitem_close',array(),$call[2]); |
||
| 189 | $this->listCalls[] = array('list'.$end[0].'_close',array(),$call[2]); |
||
| 190 | |||
| 191 | array_pop($this->listStack); |
||
| 192 | } |
||
| 193 | } |
||
| 194 | } |
||
| 195 | } |
||
| 196 | |||
| 214 |