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