Conditions | 26 |
Paths | 2355 |
Total Lines | 83 |
Code Lines | 65 |
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 |
||
150 | private function dumpItem($dumper, $cursor, &$refs, $item) |
||
151 | { |
||
152 | $cursor->refIndex = 0; |
||
153 | $cursor->softRefTo = $cursor->softRefHandle = $cursor->softRefCount = 0; |
||
154 | $cursor->hardRefTo = $cursor->hardRefHandle = $cursor->hardRefCount = 0; |
||
155 | $firstSeen = true; |
||
156 | |||
157 | if (!$item instanceof Stub) { |
||
158 | $cursor->attr = array(); |
||
159 | $type = gettype($item); |
||
160 | } elseif (Stub::TYPE_REF === $item->type) { |
||
161 | if ($item->handle) { |
||
162 | if (!isset($refs[$r = $item->handle - (PHP_INT_MAX >> 1)])) { |
||
163 | $cursor->refIndex = $refs[$r] = $cursor->refIndex ?: ++$refs[0]; |
||
164 | } else { |
||
165 | $firstSeen = false; |
||
166 | } |
||
167 | $cursor->hardRefTo = $refs[$r]; |
||
168 | $cursor->hardRefHandle = $this->useRefHandles & $item->handle; |
||
169 | $cursor->hardRefCount = $item->refCount; |
||
170 | } |
||
171 | $cursor->attr = $item->attr; |
||
172 | $type = $item->class ?: gettype($item->value); |
||
173 | $item = $item->value; |
||
174 | } |
||
175 | if ($item instanceof Stub) { |
||
176 | if ($item->refCount) { |
||
177 | if (!isset($refs[$r = $item->handle])) { |
||
178 | $cursor->refIndex = $refs[$r] = $cursor->refIndex ?: ++$refs[0]; |
||
179 | } else { |
||
180 | $firstSeen = false; |
||
181 | } |
||
182 | $cursor->softRefTo = $refs[$r]; |
||
183 | } |
||
184 | $cursor->softRefHandle = $this->useRefHandles & $item->handle; |
||
185 | $cursor->softRefCount = $item->refCount; |
||
186 | $cursor->attr = $item->attr; |
||
187 | $cut = $item->cut; |
||
188 | |||
189 | if ($item->position && $firstSeen) { |
||
190 | $children = $this->data[$item->position]; |
||
191 | |||
192 | if ($cursor->stop) { |
||
193 | if ($cut >= 0) { |
||
194 | $cut += count($children); |
||
195 | } |
||
196 | $children = array(); |
||
197 | } |
||
198 | } else { |
||
199 | $children = array(); |
||
200 | } |
||
201 | switch ($item->type) { |
||
202 | case Stub::TYPE_STRING: |
||
203 | $dumper->dumpString($cursor, $item->value, Stub::STRING_BINARY === $item->class, $cut); |
||
204 | break; |
||
205 | |||
206 | case Stub::TYPE_ARRAY: |
||
207 | $item = clone $item; |
||
208 | $item->type = $item->class; |
||
209 | $item->class = $item->value; |
||
210 | // No break; |
||
211 | case Stub::TYPE_OBJECT: |
||
212 | case Stub::TYPE_RESOURCE: |
||
213 | $withChildren = $children && $cursor->depth !== $this->maxDepth && $this->maxItemsPerDepth; |
||
214 | $dumper->enterHash($cursor, $item->type, $item->class, $withChildren); |
||
215 | if ($withChildren) { |
||
216 | $cut = $this->dumpChildren($dumper, $cursor, $refs, $children, $cut, $item->type, null !== $item->class); |
||
217 | } elseif ($children && 0 <= $cut) { |
||
218 | $cut += count($children); |
||
219 | } |
||
220 | $dumper->leaveHash($cursor, $item->type, $item->class, $withChildren, $cut); |
||
221 | break; |
||
222 | |||
223 | default: |
||
224 | throw new \RuntimeException(sprintf('Unexpected Stub type: %s', $item->type)); |
||
225 | } |
||
226 | } elseif ('array' === $type) { |
||
227 | $dumper->enterHash($cursor, Cursor::HASH_INDEXED, 0, false); |
||
228 | $dumper->leaveHash($cursor, Cursor::HASH_INDEXED, 0, false, 0); |
||
229 | } elseif ('string' === $type) { |
||
230 | $dumper->dumpString($cursor, $item, false, 0); |
||
231 | } else { |
||
232 | $dumper->dumpScalar($cursor, $type, $item); |
||
233 | } |
||
271 |