Conditions | 10 |
Paths | 10 |
Total Lines | 47 |
Code Lines | 36 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
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 |
||
105 | public function next() |
||
106 | { |
||
107 | $this->valid = false; |
||
108 | |||
109 | $style = null; |
||
110 | $type = null; |
||
111 | $columnIndex = null; |
||
112 | $rowBuilder = null; |
||
113 | $currentKey = 0; |
||
114 | |||
115 | while ($this->xml->read()) { |
||
116 | if (\XMLReader::ELEMENT === $this->xml->nodeType) { |
||
117 | switch ($this->xml->name) { |
||
118 | case 'row' : |
||
|
|||
119 | $currentKey = (int)$this->xml->getAttribute('r'); |
||
120 | $rowBuilder = $this->rowBuilderFactory->create(); |
||
121 | break; |
||
122 | case 'c' : |
||
123 | $columnIndex = $this->columnIndexTransformer->transform($this->xml->getAttribute('r')); |
||
124 | $style = $this->getValue($this->xml->getAttribute('s')); |
||
125 | $type = $this->getValue($this->xml->getAttribute('t')); |
||
126 | break; |
||
127 | case 'v' : |
||
128 | $rowBuilder->addValue( |
||
129 | $columnIndex, |
||
130 | $this->valueTransformer->transform($this->xml->readString(), $type, $style) |
||
131 | ); |
||
132 | break; |
||
133 | } |
||
134 | } elseif (\XMLReader::END_ELEMENT === $this->xml->nodeType) { |
||
135 | switch ($this->xml->name) { |
||
136 | case 'row' : |
||
137 | $currentValue = $rowBuilder->getData(); |
||
138 | if (count($currentValue)) { |
||
139 | $this->currentKey = $currentKey; |
||
140 | $this->currentValue = $currentValue; |
||
141 | $this->valid = true; |
||
142 | |||
143 | return; |
||
144 | } |
||
145 | break; |
||
146 | case 'sheetData' : |
||
147 | break 2; |
||
148 | } |
||
149 | } |
||
150 | } |
||
151 | } |
||
152 | |||
186 |
As per the PSR-2 coding standard, there must not be a space in front of the colon in case statements.
To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.