| Conditions | 10 |
| Paths | 9 |
| Total Lines | 48 |
| Code Lines | 22 |
| 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 |
||
| 18 | public function formatSymbol(DateRepresentationInterface $input, FormatToken $token, FormatterInterface $formatter) |
||
| 19 | { |
||
| 20 | if ($token->is('U')) { |
||
| 21 | // U Seconds since the Unix Epoch (January 1 1970 00:00:00 GMT) |
||
| 22 | return $input->getUnixTime(); |
||
| 23 | } |
||
| 24 | |||
| 25 | if ($token->is('u')) { |
||
| 26 | // u Microseconds |
||
| 27 | return sprintf('%06d', $input->getUnixMicroTime()); |
||
| 28 | } |
||
| 29 | |||
| 30 | if ($token->is('e')) { |
||
| 31 | // e Timezone identifier |
||
| 32 | return $input->getTimezone()->getName(); |
||
| 33 | } |
||
| 34 | |||
| 35 | if ($token->is('I')) { |
||
| 36 | // I (capital i) Whether or not the date is in daylight saving time |
||
| 37 | return (int)$input->getOffset()->isDst(); |
||
| 38 | } |
||
| 39 | |||
| 40 | if ($token->isOne('O', 'P')) { |
||
| 41 | // O Difference to Greenwich time (GMT) in hours |
||
| 42 | // P Difference to Greenwich time (GMT) with colon |
||
| 43 | $f = '%s%02d%02d'; |
||
| 44 | if ($token->is('P')) { |
||
| 45 | $f = '%s%02d:%02d'; |
||
| 46 | } |
||
| 47 | |||
| 48 | $value = intval($input->getOffset()->getValue() / 60); |
||
| 49 | |||
| 50 | return sprintf( |
||
| 51 | $f, |
||
| 52 | $value < 0 ? '-' : '+', |
||
| 53 | intval(abs($value) / 60), |
||
| 54 | intval(abs($value) % 60) |
||
| 55 | ); |
||
| 56 | } |
||
| 57 | |||
| 58 | if ($token->is('T')) { |
||
| 59 | // T Timezone abbreviation |
||
| 60 | return $input->getOffset()->getAbbreviation(); |
||
| 61 | } |
||
| 62 | |||
| 63 | if ($token->is('Z')) { |
||
| 64 | // Z Timezone offset in seconds. |
||
| 65 | return (int)$input->getOffset()->getValue(); |
||
| 66 | } |
||
| 69 |