| Conditions | 6 |
| Paths | 4 |
| Total Lines | 55 |
| Code Lines | 36 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
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 |
||
| 60 | protected function getFormSchema(): array |
||
| 61 | { |
||
| 62 | $events = NotificationEvent::where('is_active', true) |
||
| 63 | ->orderBy('group') |
||
| 64 | ->orderBy('name') |
||
| 65 | ->get(); |
||
| 66 | |||
| 67 | $activeChannels = NotificationChannel::where('is_active', true) |
||
| 68 | ->orderBy('title') |
||
| 69 | ->get(); |
||
| 70 | |||
| 71 | $groupedEvents = $events->groupBy('group'); |
||
| 72 | |||
| 73 | $sections = []; |
||
| 74 | |||
| 75 | foreach ($groupedEvents as $group => $groupEvents) { |
||
| 76 | $fields = []; |
||
| 77 | |||
| 78 | foreach ($groupEvents as $event) { |
||
| 79 | $channelCheckboxes = []; |
||
| 80 | |||
| 81 | foreach ($activeChannels as $channel) { |
||
| 82 | $channelCheckboxes[] = Checkbox::make("event_{$event->id}.{$channel->type}") |
||
| 83 | ->label($channel->title) |
||
| 84 | ->inline(false); |
||
| 85 | } |
||
| 86 | |||
| 87 | $fields[] = Grid::make([ |
||
| 88 | 'default' => 1, |
||
| 89 | 'md' => $activeChannels->count() + 1, |
||
| 90 | ]) |
||
| 91 | ->schema([ |
||
| 92 | Forms\Components\Placeholder::make("event_label_{$event->id}") |
||
| 93 | ->label($event->name) |
||
| 94 | ->content($event->description ?: '') |
||
| 95 | ->extraAttributes([ |
||
| 96 | 'class' => 'font-medium text-gray-900' |
||
| 97 | ]), |
||
| 98 | ...$channelCheckboxes, |
||
| 99 | ]) |
||
| 100 | ->extraAttributes([ |
||
| 101 | 'class' => 'border-b border-gray-200 py-4 first:pt-0 last:border-b-0 last:pb-0' |
||
| 102 | ]); |
||
| 103 | } |
||
| 104 | |||
| 105 | $sections[] = Section::make($group ?: 'General') |
||
| 106 | ->description('Configure which channels should be used for each event. These are the default channels that will be used when sending notifications for these events.') |
||
| 107 | ->schema([ |
||
| 108 | ...$fields, |
||
| 109 | ]) |
||
| 110 | ->collapsible() |
||
| 111 | ->collapsed(false); |
||
| 112 | } |
||
| 113 | |||
| 114 | return $sections; |
||
| 115 | } |
||
| 162 |