Conditions | 12 |
Paths | 288 |
Total 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 |
||
106 | public function formatDate(array $arguments, $date) |
||
107 | { |
||
108 | $format = $arguments['format']; |
||
109 | $base = $date; |
||
110 | if (is_string($base)) { |
||
111 | $base = trim($base); |
||
112 | } |
||
113 | |||
114 | if ($format === '') { |
||
115 | $format = $GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'] ?: 'Y-m-d'; |
||
116 | } |
||
117 | |||
118 | if (is_string($date)) { |
||
119 | $date = trim($date); |
||
120 | } |
||
121 | |||
122 | if ($date === '') { |
||
123 | $date = 'now'; |
||
124 | } |
||
125 | |||
126 | if (!$date instanceof \DateTimeInterface) { |
||
127 | try { |
||
128 | $base = $base instanceof \DateTimeInterface ? $base->format('U') : strtotime((MathUtility::canBeInterpretedAsInteger($base) ? '@' : '') . $base); |
||
129 | $dateTimestamp = strtotime((MathUtility::canBeInterpretedAsInteger($date) ? '@' : '') . $date, $base); |
||
130 | $date = new \DateTime('@' . $dateTimestamp); |
||
131 | $date->setTimezone(new \DateTimeZone(date_default_timezone_get())); |
||
132 | } catch (\Exception $exception) { |
||
133 | throw new Exception('"' . $date . '" could not be parsed by \DateTime constructor: ' . $exception->getMessage(), 1241722579); |
||
134 | } |
||
135 | } |
||
136 | |||
137 | if (strpos($format, '%') !== false) { |
||
138 | return strftime($format, $date->format('U')); |
||
139 | } else { |
||
140 | return $date->format($format); |
||
141 | } |
||
142 | } |
||
143 | } |
||
144 |