| Conditions | 14 |
| Paths | 7 |
| Total Lines | 57 |
| Code Lines | 46 |
| 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 |
||
| 122 | private function getElement(DOMElement $child): HolidayIteratorItemInterface |
||
| 123 | { |
||
| 124 | switch ($child->nodeName) { |
||
| 125 | case 'easter': |
||
| 126 | return new Easter( |
||
| 127 | $child->textContent, |
||
| 128 | $this->getFree($child), |
||
| 129 | (int) $child->getAttribute('offset') |
||
| 130 | ); |
||
| 131 | case 'easterorthodox': |
||
| 132 | return new EasterOrthodox( |
||
| 133 | $child->textContent, |
||
| 134 | $this->getFree($child), |
||
| 135 | (int) $child->getAttribute('offset') |
||
| 136 | ); |
||
| 137 | case 'date': |
||
| 138 | $day = CalendarDayFactory::createCalendarDay( |
||
| 139 | (int) $child->getAttribute('day'), |
||
| 140 | (int) $child->getAttribute('month'), |
||
| 141 | ($child->hasAttribute('calendar')?$child->getAttribute('calendar'): 'gregorian') |
||
| 142 | ); |
||
| 143 | if ($child->hasAttribute('year')) { |
||
| 144 | $day->setYear((int) $child->getAttribute('year')); |
||
| 145 | } |
||
| 146 | return new Date( |
||
| 147 | $child->textContent, |
||
| 148 | $this->getFree($child), |
||
| 149 | $day, |
||
| 150 | $child->hasAttribute('forwardto')?$child->getAttribute('forwardto'):'', |
||
| 151 | $child->hasAttribute('forwardwhen')?explode(' ', $child->getAttribute('forwardwhen')):[], |
||
| 152 | $child->hasAttribute('rewindto')?$child->getAttribute('rewindto'):'', |
||
| 153 | $child->hasAttribute('rewindwhen')?explode(' ', $child->getAttribute('rewindwhen')):[], |
||
| 154 | ); |
||
| 155 | case 'dateFollowUp': |
||
| 156 | $day = CalendarDayFactory::createCalendarDay( |
||
| 157 | (int) $child->getAttribute('day'), |
||
| 158 | (int) $child->getAttribute('month'), |
||
| 159 | ($child->hasAttribute('calendar')?$child->getAttribute('calendar'): 'gregorian') |
||
| 160 | ); |
||
| 161 | |||
| 162 | return new DateFollowUp( |
||
| 163 | $child->textContent, |
||
| 164 | $this->getFree($child), |
||
| 165 | $day, |
||
| 166 | $child->getAttribute('followup'), |
||
| 167 | ($child->hasAttribute('replaced')?explode(' ', $child->getAttribute('replaced')):[]) |
||
| 168 | ); |
||
| 169 | case 'relative': |
||
| 170 | return new Relative( |
||
| 171 | $child->textContent, |
||
| 172 | $this->getFree($child), |
||
| 173 | (int) $child->getAttribute('day'), |
||
| 174 | (int) $child->getAttribute('month'), |
||
| 175 | $child->getAttribute('relation') |
||
| 176 | ); |
||
| 177 | default: |
||
| 178 | throw new RuntimeException('Unknown element encountered'); |
||
| 179 | } |
||
| 187 |