Conditions | 12 |
Paths | 512 |
Total Lines | 85 |
Code Lines | 59 |
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 |
||
55 | public function handle(ServerRequestInterface $request): ResponseInterface |
||
56 | { |
||
57 | $tree = Validator::attributes($request)->tree(); |
||
58 | $view = Validator::attributes($request)->isInArray(['day', 'month', 'year'])->string('view'); |
||
59 | $cal = Validator::queryParams($request)->string('cal', ''); |
||
60 | $day = Validator::queryParams($request)->string('day', ''); |
||
61 | $month = Validator::queryParams($request)->string('month', ''); |
||
62 | $year = Validator::queryParams($request)->string('year', ''); |
||
63 | $filterev = Validator::queryParams($request)->string('filterev', 'BIRT-MARR-DEAT'); |
||
64 | $filterof = Validator::queryParams($request)->string('filterof', 'all'); |
||
65 | $filtersx = Validator::queryParams($request)->string('filtersx', ''); |
||
66 | |||
67 | if ($cal . $day . $month . $year === '') { |
||
68 | // No date specified? Use the most likely calendar |
||
69 | $cal = I18N::language()->calendar()->gedcomCalendarEscape(); |
||
70 | } |
||
71 | |||
72 | // need BC to parse date |
||
73 | if (str_starts_with($year, '-')) { |
||
74 | $year = substr($year, 1) . ' B.C.'; |
||
75 | } |
||
76 | $ged_date = new Date($cal . ' ' . $day . ' ' . $month . ' ' . $year); |
||
77 | // need negative year for year entry field. |
||
78 | $year = $ged_date->minimumDate()->year; |
||
79 | $cal_date = $ged_date->minimumDate(); |
||
80 | |||
81 | // Fill in any missing bits with todays date |
||
82 | $today = $cal_date->today(); |
||
83 | if ($cal_date->day === 0) { |
||
84 | $cal_date->day = $today->day; |
||
85 | } |
||
86 | if ($cal_date->month === 0) { |
||
87 | $cal_date->month = $today->month; |
||
88 | } |
||
89 | if ($cal_date->year === 0) { |
||
90 | $cal_date->year = $today->year; |
||
91 | } |
||
92 | |||
93 | $cal_date->setJdFromYmd(); |
||
94 | |||
95 | if ($year === 0) { |
||
96 | $year = $cal_date->year; |
||
97 | } |
||
98 | |||
99 | // Extract values from date |
||
100 | $days_in_month = $cal_date->daysInMonth(); |
||
101 | $cal_month = $cal_date->format('%O'); |
||
102 | $today_month = $today->format('%O'); |
||
103 | |||
104 | // Invalid dates? Go to monthly view, where they'll be found. |
||
105 | if ($cal_date->day > $days_in_month && $view === 'day') { |
||
106 | $view = 'month'; |
||
107 | } |
||
108 | |||
109 | $title = I18N::translate('Anniversary calendar'); |
||
110 | |||
111 | switch ($view) { |
||
112 | case 'day': |
||
113 | $title = I18N::translate('On this day…') . ' ' . $ged_date->display($tree); |
||
114 | break; |
||
115 | case 'month': |
||
116 | $title = I18N::translate('In this month…') . ' ' . $ged_date->display($tree, '%F %Y'); |
||
117 | break; |
||
118 | case 'year': |
||
119 | $title = I18N::translate('In this year…') . ' ' . $ged_date->display($tree, '%Y'); |
||
120 | break; |
||
121 | } |
||
122 | |||
123 | return $this->viewResponse('calendar-page', [ |
||
124 | 'cal' => $cal, |
||
125 | 'cal_date' => $cal_date, |
||
126 | 'cal_month' => $cal_month, |
||
127 | 'day' => $day, |
||
128 | 'days_in_month' => $days_in_month, |
||
129 | 'filterev' => $filterev, |
||
130 | 'filterof' => $filterof, |
||
131 | 'filtersx' => $filtersx, |
||
132 | 'month' => $month, |
||
133 | 'months' => $this->calendar_service->calendarMonthsInYear($cal, $year), |
||
134 | 'title' => $title, |
||
135 | 'today' => $today, |
||
136 | 'today_month' => $today_month, |
||
137 | 'tree' => $tree, |
||
138 | 'view' => $view, |
||
139 | 'year' => $year, |
||
140 | ]); |
||
143 |