| Conditions | 9 |
| Paths | 14 |
| Total Lines | 56 |
| Code Lines | 35 |
| 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 |
||
| 84 | private function getFormattedTimestamp( TimeValue $value ) { |
||
| 85 | $formatter = $this->getOption( self::OPT_TIME_ISO_FORMATTER ); |
||
| 86 | |||
| 87 | if ( $formatter instanceof ValueFormatter ) { |
||
| 88 | return $formatter->format( $value ); |
||
| 89 | } |
||
| 90 | |||
| 91 | if ( !preg_match( |
||
| 92 | // Loose check for ISO-like strings, as used in Gregorian and Julian time values. |
||
| 93 | '/^([-+]?)(\d+)-(\d+)-(\d+)(?:T(\d+):(\d+)(?::(\d+))?)?Z?$/i', |
||
| 94 | $value->getTime(), |
||
| 95 | $matches |
||
| 96 | ) ) { |
||
| 97 | return $value->getTime(); |
||
| 98 | } |
||
| 99 | |||
| 100 | list( , $sign, $year, $month, $day, $hour, $minute, $second ) = $matches; |
||
| 101 | |||
| 102 | // Actual MINUS SIGN (U+2212) instead of HYPHEN-MINUS (U+002D) |
||
| 103 | $sign = $sign === '-' ? "\xE2\x88\x92" : ''; |
||
| 104 | |||
| 105 | // Warning, never cast the year to integer to not run into 32-bit integer overflows! |
||
| 106 | $year = ltrim( $year, '0' ); |
||
| 107 | |||
| 108 | if ( $value->getPrecision() <= TimeValue::PRECISION_YEAR ) { |
||
| 109 | return sprintf( '%s%04s', $sign, $year ); |
||
| 110 | } |
||
| 111 | |||
| 112 | switch ( $value->getPrecision() ) { |
||
| 113 | case TimeValue::PRECISION_MONTH: |
||
| 114 | return sprintf( |
||
| 115 | '%s%04s-%02s', |
||
| 116 | $sign, $year, $month |
||
| 117 | ); |
||
| 118 | case TimeValue::PRECISION_DAY: |
||
| 119 | return sprintf( |
||
| 120 | '%s%04s-%02s-%02s', |
||
| 121 | $sign, $year, $month, $day |
||
| 122 | ); |
||
| 123 | case TimeValue::PRECISION_HOUR: |
||
| 124 | return sprintf( |
||
| 125 | '%s%04s-%02s-%02sT%02s', |
||
| 126 | $sign, $year, $month, $day, $hour |
||
| 127 | ); |
||
| 128 | case TimeValue::PRECISION_MINUTE: |
||
| 129 | return sprintf( |
||
| 130 | '%s%04s-%02s-%02sT%02s:%02s', |
||
| 131 | $sign, $year, $month, $day, $hour, $minute |
||
| 132 | ); |
||
| 133 | default: |
||
| 134 | return sprintf( |
||
| 135 | '%s%04s-%02s-%02sT%02s:%02s:%02s', |
||
| 136 | $sign, $year, $month, $day, $hour, $minute, $second |
||
| 137 | ); |
||
| 138 | } |
||
| 139 | } |
||
| 140 | |||
| 157 |