| Conditions | 11 |
| Paths | 42 |
| Total Lines | 60 |
| Code Lines | 37 |
| 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 |
||
| 31 | public function getIcalForTimezone() { |
||
| 32 | if ( $this->m_from === null || $this->m_to === null ) |
||
| 33 | return false; |
||
| 34 | |||
| 35 | try { |
||
| 36 | $timezone = new DateTimeZone( $this->m_tzid ); |
||
| 37 | } catch( Exception $e ) { |
||
| 38 | return false; |
||
| 39 | } |
||
| 40 | |||
| 41 | $transitions = $timezone->getTransitions(); |
||
| 42 | |||
| 43 | $min = 0; |
||
| 44 | $max = 1; |
||
| 45 | foreach ( $transitions as $i => $transition ) { |
||
| 46 | if ( $transition['ts'] < $this->m_from ) { |
||
| 47 | $min = $i; |
||
| 48 | continue; |
||
| 49 | } |
||
| 50 | |||
| 51 | if ( $transition['ts'] > $this->m_to ) { |
||
| 52 | $max = $i; |
||
| 53 | break; |
||
| 54 | } |
||
| 55 | } |
||
| 56 | |||
| 57 | // cf. http://www.kanzaki.com/docs/ical/vtimezone.html |
||
| 58 | $result = "BEGIN:VTIMEZONE\r\n"; |
||
| 59 | $result .= "TZID:{$this->m_tzid}\r\n"; |
||
| 60 | |||
| 61 | $transition = ( $min > 0 ) ? $transitions[$min-1] : $transitions[0]; |
||
| 62 | $tzfrom = $transition['offset'] / 3600; |
||
| 63 | |||
| 64 | foreach ( array_slice( $transitions, $min, $max - $min ) as $transition) { |
||
| 65 | $dst = ( $transition['isdst'] ) ? "DAYLIGHT" : "STANDARD"; |
||
| 66 | $result .= "BEGIN:$dst\r\n"; |
||
| 67 | |||
| 68 | $start_date = date( 'Ymd\THis', $transition['ts'] ); |
||
| 69 | $result .= "DTSTART:$start_date\r\n"; |
||
| 70 | |||
| 71 | $offset = $transition['offset'] / 3600; |
||
| 72 | |||
| 73 | $offset_from = $this->formatTimezoneOffset( $tzfrom ); |
||
| 74 | $result .= "TZOFFSETFROM:$offset_from\r\n"; |
||
| 75 | |||
| 76 | $offset_to = $this->formatTimezoneOffset( $offset ); |
||
| 77 | $result .= "TZOFFSETTO:$offset_to\r\n"; |
||
| 78 | |||
| 79 | if ( !empty( $transition['abbr'] ) ) |
||
| 80 | $result .= "TZNAME:{$transition['abbr']}\r\n"; |
||
| 81 | |||
| 82 | $result .= "END:$dst\r\n"; |
||
| 83 | |||
| 84 | $tzfrom = $offset; |
||
| 85 | } |
||
| 86 | |||
| 87 | $result .= "END:VTIMEZONE\r\n"; |
||
| 88 | |||
| 89 | return $result; |
||
| 90 | } |
||
| 91 | |||
| 101 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italyis not defined by the methodfinale(...).The most likely cause is that the parameter was removed, but the annotation was not.