Conditions | 26 |
Paths | 138 |
Total Lines | 100 |
Code Lines | 64 |
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 |
||
91 | public function getBlock(Tree $tree, int $block_id, string $context, array $config = []): string |
||
92 | { |
||
93 | $calendar_service = new CalendarService(); |
||
94 | |||
95 | $days = (int) $this->getBlockSetting($block_id, 'days', self::DEFAULT_DAYS); |
||
96 | $infoStyle = $this->getBlockSetting($block_id, 'infoStyle', self::DEFAULT_STYLE); |
||
97 | $calendar = $this->getBlockSetting($block_id, 'calendar', self::DEFAULT_CALENDAR); |
||
98 | |||
99 | extract($config, EXTR_OVERWRITE); |
||
100 | |||
101 | $jewish_calendar = new JewishCalendar(); |
||
102 | $startjd = Registry::timestampFactory()->now()->julianDay(); |
||
103 | $endjd = Registry::timestampFactory()->now()->addDays($days - 1)->julianDay(); |
||
104 | |||
105 | // The standard anniversary rules cover most of the Yahrzeit rules, we just |
||
106 | // need to handle a few special cases. |
||
107 | // Fetch normal anniversaries, with an extra day before/after |
||
108 | $yahrzeits = new Collection(); |
||
109 | for ($jd = $startjd - 1; $jd <= $endjd + $days; ++$jd) { |
||
110 | foreach ($calendar_service->getAnniversaryEvents($jd, 'DEAT _YART', $tree) as $fact) { |
||
111 | // Exact hebrew dates only |
||
112 | $date = $fact->date(); |
||
113 | if ($date->minimumDate() instanceof JewishDate && $date->minimumJulianDay() === $date->maximumJulianDay()) { |
||
114 | $jd_yahrtzeit = $jd; |
||
115 | // ...then adjust DEAT dates (but not _YART) |
||
116 | if ($fact->tag() === 'INDI:DEAT') { |
||
117 | $today = new JewishDate($jd); |
||
118 | $hd = $fact->date()->minimumDate(); |
||
119 | $hd1 = new JewishDate($hd); |
||
120 | ++$hd1->year; |
||
121 | $hd1->setJdFromYmd(); |
||
122 | // Special rules. See https://www.hebcal.com/help/anniv.html |
||
123 | // Everything else is taken care of by our standard anniversary rules. |
||
124 | if ($hd->day === 30 && $hd->month === 2 && $hd->year !== 0 && $hd1->daysInMonth() < 30) { |
||
125 | // 30 CSH - Last day in CSH |
||
126 | $jd_yahrtzeit = $jewish_calendar->ymdToJd($today->year, 3, 1) - 1; |
||
127 | } elseif ($hd->day === 30 && $hd->month === 3 && $hd->year !== 0 && $hd1->daysInMonth() < 30) { |
||
128 | // 30 KSL - Last day in KSL |
||
129 | $jd_yahrtzeit = $jewish_calendar->ymdToJd($today->year, 4, 1) - 1; |
||
130 | } elseif ($hd->day === 30 && $hd->month === 6 && $hd->year !== 0 && $today->daysInMonth() < 30 && !$today->isLeapYear()) { |
||
131 | // 30 ADR - Last day in SHV |
||
132 | $jd_yahrtzeit = $jewish_calendar->ymdToJd($today->year, 6, 1) - 1; |
||
133 | } |
||
134 | } |
||
135 | |||
136 | // Filter adjusted dates to our date range |
||
137 | if ($jd_yahrtzeit >= $startjd && $jd_yahrtzeit < $startjd + $days) { |
||
138 | // upcoming yahrzeit dates |
||
139 | switch ($calendar) { |
||
140 | case 'gregorian': |
||
141 | $yahrzeit_calendar_date = new GregorianDate($jd_yahrtzeit); |
||
142 | break; |
||
143 | case 'jewish': |
||
144 | default: |
||
145 | $yahrzeit_calendar_date = new JewishDate($jd_yahrtzeit); |
||
146 | break; |
||
147 | } |
||
148 | $yahrzeit_date = new Date($yahrzeit_calendar_date->format('%@ %A %O %E')); |
||
149 | |||
150 | $yahrzeits->add((object) [ |
||
151 | 'individual' => $fact->record(), |
||
152 | 'fact_date' => $fact->date(), |
||
153 | 'fact' => $fact, |
||
154 | 'yahrzeit_date' => $yahrzeit_date, |
||
155 | ]); |
||
156 | } |
||
157 | } |
||
158 | } |
||
159 | } |
||
160 | |||
161 | switch ($infoStyle) { |
||
162 | case 'list': |
||
163 | $content = view('modules/yahrzeit/list', [ |
||
164 | 'id' => $block_id, |
||
165 | 'limit_low' => self::LIMIT_LOW, |
||
166 | 'limit_high' => self::LIMIT_HIGH, |
||
167 | 'yahrzeits' => $yahrzeits, |
||
168 | ]); |
||
169 | break; |
||
170 | case 'table': |
||
171 | default: |
||
172 | $content = view('modules/yahrzeit/table', [ |
||
173 | 'limit_low' => self::LIMIT_LOW, |
||
174 | 'limit_high' => self::LIMIT_HIGH, |
||
175 | 'yahrzeits' => $yahrzeits, |
||
176 | ]); |
||
177 | break; |
||
178 | } |
||
179 | |||
180 | if ($context !== self::CONTEXT_EMBED) { |
||
181 | return view('modules/block-template', [ |
||
182 | 'block' => Str::kebab($this->name()), |
||
183 | 'id' => $block_id, |
||
184 | 'config_url' => $this->configUrl($tree, $context, $block_id), |
||
185 | 'title' => $this->title(), |
||
186 | 'content' => $content, |
||
187 | ]); |
||
188 | } |
||
189 | |||
190 | return $content; |
||
191 | } |
||
280 |