Conditions | 12 |
Paths | 21 |
Total Lines | 49 |
Code Lines | 36 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 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 |
||
28 | public function exportEvents(Iterator $events): ?NodeValueInterface |
||
29 | { |
||
30 | $buffer = []; |
||
31 | $structures = []; |
||
32 | $structure = null; |
||
33 | foreach ($events as $event) { |
||
34 | switch (true) { |
||
35 | case $event instanceof ScalarEventInterface: |
||
36 | $buffer[] = $event->getData(); |
||
37 | break; |
||
38 | |||
39 | case $event instanceof BeforeArrayEventInterface: |
||
40 | case $event instanceof BeforeObjectEventInterface: |
||
41 | $structures[] = $structure; |
||
42 | $structure = []; |
||
43 | break; |
||
44 | |||
45 | case $event instanceof BeforeElementEventInterface: |
||
46 | case $event instanceof BeforePropertyEventInterface: |
||
47 | break; |
||
48 | |||
49 | case $event instanceof AfterElementEventInterface: |
||
50 | $structure[$event->getIndex()] = array_pop($buffer); |
||
51 | break; |
||
52 | |||
53 | case $event instanceof AfterPropertyEventInterface: |
||
54 | $structure[$event->getName()] = array_pop($buffer); |
||
55 | break; |
||
56 | |||
57 | case $event instanceof AfterArrayEventInterface: |
||
58 | $buffer[] = $structure; |
||
59 | $structure = array_pop($structures); |
||
60 | break; |
||
61 | |||
62 | case $event instanceof AfterObjectEventInterface: |
||
63 | $buffer[] = (object) $structure; |
||
64 | $structure = array_pop($structures); |
||
65 | break; |
||
66 | |||
67 | default: |
||
68 | throw new Exception\UnknownEventException($event); |
||
69 | } |
||
70 | } |
||
71 | if (empty($buffer)) { |
||
72 | return null; |
||
73 | } |
||
74 | $data = array_pop($buffer); |
||
75 | |||
76 | return (new NodeValueFactory())->createValue($data); |
||
77 | } |
||
89 |