Conditions | 16 |
Paths | 16 |
Total Lines | 88 |
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 |
||
39 | public function formatSymbol(DateRepresentationInterface $input, FormatToken $token, FormatterInterface $formatter) |
||
40 | { |
||
41 | if (!$input instanceof DateFragmentedRepresentationInterface) { |
||
42 | return; |
||
43 | } |
||
44 | |||
45 | if ($token->is('F')) { |
||
46 | // F A full textual representation of a month |
||
47 | return (string)$this->locale->getMonthName( |
||
48 | $input->getDateParts()->get(0) |
||
49 | ); |
||
50 | } |
||
51 | |||
52 | if ($token->is('M')) { |
||
53 | // M A short textual representation of a month, three letters |
||
54 | return (string)$this->locale->getMonthShortName( |
||
55 | $input->getDateParts()->get(0) |
||
56 | ); |
||
57 | } |
||
58 | |||
59 | if ($token->is('m')) { |
||
60 | // m Numeric representation of a month, with leading zeros |
||
61 | return sprintf('%02d', $input->getDateParts()->get(0) + 1); |
||
62 | } |
||
63 | |||
64 | if ($token->is('n')) { |
||
65 | // n Numeric representation of a month, without leading zeros |
||
66 | return $input->getDateParts()->get(0) + 1; |
||
67 | } |
||
68 | |||
69 | if ($token->is('t')) { |
||
70 | // t Number of days in the given month |
||
71 | return (int)$input->getDateParts()->getSize(0); |
||
72 | } |
||
73 | |||
74 | if ($token->is('d')) { |
||
75 | // d Day of the month, 2 digits with leading zeros |
||
76 | return sprintf('%02d', $input->getDateParts()->get(1) + 1); |
||
77 | } |
||
78 | |||
79 | if ($token->is('j')) { |
||
80 | // j Day of the month without leading zeros |
||
81 | return $input->getDateParts()->get(1) + 1; |
||
82 | } |
||
83 | |||
84 | if ($token->is('S')) { |
||
85 | // S English ordinal suffix for the day of the month, 2 characters |
||
86 | return $this->locale->getNumberOrdinalSuffix( |
||
87 | (int)$input->getDateParts()->get(1) |
||
88 | ); |
||
89 | } |
||
90 | |||
91 | if ($token->is('l')) { |
||
92 | // l (lowercase 'L') A full textual representation of the day of the week |
||
93 | return (string)$this->locale->getDayName( |
||
94 | $input->getDateParts()->getTransversal(2) |
||
95 | ); |
||
96 | } |
||
97 | |||
98 | if ($token->is('D')) { |
||
99 | // D A textual representation of a day, three letters |
||
100 | return (string)$this->locale->getDayShortName( |
||
101 | $input->getDateParts()->getTransversal(2) |
||
102 | ); |
||
103 | } |
||
104 | |||
105 | if ($token->is('w')) { |
||
106 | // w Numeric representation of the day of the week 0 (for Sunday) through 6 (for Saturday) |
||
107 | return (1 + $input->getDateParts()->getTransversal(2)) % 7; |
||
108 | } |
||
109 | |||
110 | if ($token->is('N')) { |
||
111 | // N ISO-8601 numeric representation of the day of the week (added in PHP 5.1.0) 1 (for Monday) through 7 (for Sunday) |
||
112 | return $input->getDateParts()->getTransversal(2) + 1; |
||
113 | } |
||
114 | |||
115 | if ($token->is('W')) { |
||
116 | // W ISO-8601 week number of year, weeks starting on Monday |
||
117 | return sprintf( |
||
118 | '%02d', |
||
119 | $input->getDateParts()->getTransversal(1) + 1 |
||
120 | ); |
||
121 | } |
||
122 | |||
123 | if ($token->is('o')) { |
||
124 | // Y A full numeric representation of a year, 4 digits |
||
125 | // o ISO-8601 week-numbering year. This has the same value as Y, except that if the ISO week number (W) belongs to the previous or next year, that year is used instead. |
||
126 | return sprintf('%04d', $input->getDateParts()->getTransversal(0)); |
||
127 | } |
||
130 |