| Conditions | 15 |
| Paths | 17 |
| Total Lines | 61 |
| Code Lines | 26 |
| 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 |
||
| 21 | public function formatSymbol(DateRepresentationInterface $input, FormatToken $token, FormatterInterface $formatter) |
||
| 22 | { |
||
| 23 | if (!$input instanceof DateTimeRepresentationInterface) { |
||
| 24 | return; |
||
| 25 | } |
||
| 26 | |||
| 27 | if ($token->isOne('a', 'A')) { |
||
| 28 | // a Lowercase Ante meridiem and Post meridiem am or pm |
||
| 29 | // A Uppercase Ante meridiem and Post meridiem AM or PM |
||
| 30 | $res = $input->getTime()->canBeHalved(0) ? 'pm' : 'am'; |
||
| 31 | return $token->is('a') ? $res : strtoupper($res); |
||
| 32 | } |
||
| 33 | |||
| 34 | if ($token->is('B')) { |
||
| 35 | // B Swatch Internet time 000 through 999 |
||
| 36 | return sprintf('%03d', $input->getTime()->getTransversal(0)); |
||
| 37 | } |
||
| 38 | |||
| 39 | if ($token->isOne('g', 'h')) { |
||
| 40 | // g 12-hour format of an hour without leading zeros 1 through 12 |
||
| 41 | // h 12-hour format of an hour with leading zeros 01 through 12 |
||
| 42 | $res = $input->getTime()->getHalved(0); |
||
| 43 | if (!$res) { |
||
|
|
|||
| 44 | $res = (integer)floor($input->getTime()->getSize(0) / 2); |
||
| 45 | } |
||
| 46 | |||
| 47 | if ($token->is('h')) { |
||
| 48 | return sprintf('%02d', $res); |
||
| 49 | } |
||
| 50 | |||
| 51 | return (string)$res; |
||
| 52 | } |
||
| 53 | |||
| 54 | if ($token->is('G')) { |
||
| 55 | // G 24-hour format of an hour without leading zeros 0 through 23 |
||
| 56 | return $input->getTime()->get(0); |
||
| 57 | } |
||
| 58 | |||
| 59 | if ($token->is('H')) { |
||
| 60 | // H 24-hour format of an hour with leading zeros 00 through 23 |
||
| 61 | return sprintf('%02d', $input->getTime()->get(0)); |
||
| 62 | } |
||
| 63 | |||
| 64 | if ($token->is('i')) { |
||
| 65 | // i Minutes with leading zeros 00 to 59 |
||
| 66 | return sprintf('%02d', $input->getTime()->get(1)); |
||
| 67 | } |
||
| 68 | |||
| 69 | if ($token->is('s')) { |
||
| 70 | // s Seconds, with leading zeros 00 through 59 |
||
| 71 | return sprintf('%02d', $input->getTime()->get(2)); |
||
| 72 | } |
||
| 73 | |||
| 74 | if ($token->is('v')) { |
||
| 75 | // v Milliseconds |
||
| 76 | return sprintf('%03d', intval($input->getTime()->get(3))); |
||
| 77 | } |
||
| 78 | |||
| 79 | if ($token->is('µ')) { |
||
| 80 | // Remaining microseconds |
||
| 81 | return sprintf('%03d', intval($input->getTime()->get(4))); |
||
| 82 | } |
||
| 85 |
In PHP, under loose comparison (like
==, or!=, orswitchconditions), values of different types might be equal.For
integervalues, zero is a special case, in particular the following results might be unexpected: