Conditions | 11 |
Paths | 136 |
Total Lines | 44 |
Code Lines | 26 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 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 |
||
26 | public function monthsSelectGenerator( |
||
27 | string $id, |
||
28 | string $class, |
||
29 | string $name, |
||
30 | bool $currentSelected = false, |
||
31 | array $dataAtributes = null) |
||
32 | { |
||
33 | $dataAttr = $dataAtributes ? implode(" ", $dataAtributes) : ''; |
||
34 | |||
35 | $currentYear = (new \DateTime('now'))->format('Y'); |
||
36 | $currentMonth = $currentSelected ? (new \DateTime('now'))->format('m') : ''; |
||
37 | $months = 12; |
||
38 | $options = ""; |
||
39 | $formatter = ''; |
||
40 | |||
41 | if ($this->language == 'pt_br') |
||
42 | { |
||
43 | $formatter = \IntlDateFormatter::create( |
||
44 | 'pt_BR', |
||
45 | \IntlDateFormatter::FULL, |
||
46 | \IntlDateFormatter::NONE, |
||
47 | 'America/Sao_Paulo', |
||
48 | \IntlDateFormatter::GREGORIAN, |
||
49 | $this->monthFormat == 'small' ? 'MMM' : 'MMMM' |
||
50 | ); |
||
51 | } |
||
52 | |||
53 | for ($i = 1; $i <= $months; $i++) |
||
54 | { |
||
55 | $digit = $i < 10 ? '0' . $i : $i; |
||
56 | $currentDate = "{$currentYear}-{$digit}-20"; |
||
57 | $selected = $currentMonth == $digit ? 'selected' : ''; |
||
58 | $formatedMonth = $formatter != '' |
||
59 | ? ucwords($formatter->format((new \DateTime($currentDate)))) |
||
60 | : (new \DateTime($currentDate))->format($this->monthFormat == 'small' ? 'M' : 'F'); |
||
61 | |||
62 | $value = $this->valueFormat == 'number' |
||
63 | ? $i |
||
64 | : strtolower(str_replace("ç", 'c', $formatedMonth)); |
||
65 | |||
66 | $options .= "<option value='{$value}' {$selected}>{$formatedMonth}</option>"; |
||
67 | } |
||
68 | |||
69 | return "<select id='{$id}' class='{$class}' name='{$name}' {$dataAttr}>{$options}</select>"; |
||
70 | } |
||
72 |