Conditions | 16 |
Paths | 23 |
Total Lines | 66 |
Code Lines | 37 |
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 |
||
44 | public function process() |
||
45 | { |
||
46 | $reader = $this->getReader(); |
||
47 | |||
48 | $recipientChain = []; |
||
49 | |||
50 | while($reader->read()) |
||
51 | { |
||
52 | $nodeType = $reader->nodeType; |
||
53 | |||
54 | switch ($nodeType) |
||
55 | { |
||
56 | case \XMLReader::END_ELEMENT: |
||
57 | if (!in_array($reader->name, $this->convertToAttribute, true) && count($recipientChain) !== 1) { |
||
58 | $recipientChain = array_slice($recipientChain, 0, -1); |
||
59 | } |
||
60 | |||
61 | break; |
||
62 | case \XMLReader::ELEMENT: |
||
63 | $recipient = end($recipientChain); |
||
64 | $isConverted = false; |
||
65 | |||
66 | if ($recipient && $recipient->_childrenProperty === null) { |
||
67 | if ($isConverted = in_array($reader->name, $this->convertToAttribute, true)) { |
||
68 | $recipient->_childrenProperty = $reader->name; |
||
69 | |||
70 | break; |
||
71 | } else { |
||
72 | $recipient->_childrenProperty = $this->childrenProperty; |
||
73 | } |
||
74 | } |
||
75 | |||
76 | $node = new Node(); |
||
77 | $node->_tagName = $reader->name; |
||
78 | |||
79 | $hasAttributes = $reader->hasAttributes; |
||
80 | $isEmptyElement = $reader->isEmptyElement; |
||
81 | |||
82 | if ($hasAttributes) { |
||
83 | while($reader->moveToNextAttribute()) { |
||
84 | $node->{$reader->name} = $reader->value; |
||
85 | } |
||
86 | } |
||
87 | |||
88 | if ($recipient) { |
||
89 | $recipient->{$recipient->_childrenProperty}[] = $node; |
||
90 | } |
||
91 | |||
92 | if (!$isEmptyElement && !$isConverted) { |
||
93 | $recipientChain[] = $node; |
||
94 | } |
||
95 | |||
96 | break; |
||
97 | case \XMLReader::TEXT: |
||
|
|||
98 | |||
99 | break; |
||
100 | case \XMLReader::ATTRIBUTE: |
||
101 | |||
102 | break; |
||
103 | } |
||
104 | } |
||
105 | |||
106 | $reader->close(); |
||
107 | |||
108 | return $recipientChain[0]; |
||
109 | } |
||
110 | |||
123 |
According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.
}
To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.