Conditions | 7 |
Paths | 8 |
Total Lines | 59 |
Code Lines | 36 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
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 |
||
35 | protected function schedule(Schedule $schedule) |
||
36 | { |
||
37 | $schedule->call(function () { |
||
38 | Log::info('Sending attendance reminders'); |
||
39 | $this->remindPendingAttendance(); |
||
40 | })->dailyAt('08:15'); |
||
41 | |||
42 | $schedule->call(function () { |
||
43 | Log::info('Checking default periods'); |
||
44 | |||
45 | // when we finish the current period; remove the manual override to automatically fallbackto the next one |
||
46 | $changeCurrentPeriod = Carbon::parse(Period::get_default_period()->end) < Carbon::now(); |
||
47 | if ($changeCurrentPeriod) { |
||
48 | Log::info('Removing manual current period override'); |
||
49 | Config::where('name', 'current_period')->update(['value' => null]); |
||
50 | } |
||
51 | |||
52 | // if the enrollment period is the same as the current period, we can remove it |
||
53 | if (Period::get_enrollments_period() == Period::get_default_period()) { |
||
54 | Log::info('Removing manual enrollment period override'); |
||
55 | Config::where('name', 'default_enrollment_period')->update(['value' => null]); |
||
56 | } |
||
57 | })->dailyAt('00:00'); |
||
58 | |||
59 | if (config('settings.partnership_alerts')) { |
||
60 | $schedule->call(function () { |
||
61 | Log::info('Checking expired partnerships'); |
||
62 | |||
63 | // if one of the partnerships is expiring soon, send an email |
||
64 | $partners = Partner::where(function ($query) { |
||
65 | $query->whereNotNull('expired_on')->where('expired_on', '<', Carbon::now()->addDays(28)); |
||
66 | }) |
||
67 | ->where(function ($query) { |
||
68 | $query->whereNull('last_alert_sent_at')->orWhere('last_alert_sent_at', '>', Carbon::now()->subDays(28))->get(); |
||
69 | }); |
||
70 | |||
71 | if ($partners->count() > 0) { |
||
72 | event(new ExpiringPartnershipsEvent($partners->get())); |
||
73 | } |
||
74 | })->dailyAt('02:05'); |
||
75 | } |
||
76 | |||
77 | if (config('settings.external_courses_report')) { |
||
78 | $schedule->call(function () { |
||
79 | Log::info('Sending external courses reports'); |
||
80 | event(new ExternalCoursesReportEvent()); |
||
81 | })->dailyAt('02:10'); |
||
82 | } |
||
83 | |||
84 | if (config('settings.monthly_report')) { |
||
85 | $schedule->call(function () { |
||
86 | Log::info('Sending monthly hours report'); |
||
87 | event(new MonthlyReportEvent()); |
||
88 | })->monthlyOn(20); |
||
89 | } |
||
90 | |||
91 | $schedule->command('activitylog:clean')->daily(); |
||
92 | |||
93 | $schedule->command('telescope:prune --hours=96')->daily(); |
||
94 | } |
||
108 |