| Conditions | 2 |
| Paths | 2 |
| Total Lines | 110 |
| Code Lines | 95 |
| 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 |
||
| 77 | public function form(Schema $schema): Schema |
||
| 78 | { |
||
| 79 | $channels = NotificationChannel::all(); |
||
| 80 | $tabs = [ |
||
| 81 | Tab::make('General') |
||
| 82 | ->icon('heroicon-o-cog') |
||
| 83 | ->schema([ |
||
| 84 | Toggle::make('enabled') |
||
| 85 | ->label('Enable Notifications') |
||
| 86 | ->default(true), |
||
| 87 | TextInput::make('queue_name') |
||
| 88 | ->label('Queue Name') |
||
| 89 | ->default('default') |
||
| 90 | ->required(), |
||
| 91 | Select::make('default_channel') |
||
| 92 | ->label('Default Channel') |
||
| 93 | ->options(NotificationChannel::pluck('title', 'type')->toArray()) |
||
| 94 | ->required(), |
||
| 95 | ]), |
||
| 96 | Tab::make('Preferences') |
||
| 97 | ->icon('heroicon-o-user-circle') |
||
| 98 | ->schema([ |
||
| 99 | Section::make('User Preferences') |
||
| 100 | ->description('Configure default user notification preferences') |
||
| 101 | ->schema([ |
||
| 102 | Toggle::make('preferences.enabled') |
||
| 103 | ->label('Enable User Preferences') |
||
| 104 | ->default(true), |
||
| 105 | Select::make('preferences.default_channels') |
||
| 106 | ->label('Default Channels') |
||
| 107 | ->multiple() |
||
| 108 | ->options(NotificationChannel::pluck('title', 'type')->toArray()) |
||
| 109 | ->default(['email']) |
||
| 110 | ->required(), |
||
| 111 | Toggle::make('preferences.allow_override') |
||
| 112 | ->label('Allow Users to Override Preferences') |
||
| 113 | ->default(true) |
||
| 114 | ->helperText('If enabled, users can customize their notification preferences'), |
||
| 115 | ]), |
||
| 116 | ]), |
||
| 117 | Tab::make('Analytics') |
||
| 118 | ->icon('heroicon-o-chart-bar') |
||
| 119 | ->schema([ |
||
| 120 | Section::make('Analytics Settings') |
||
| 121 | ->description('Configure notification analytics and tracking') |
||
| 122 | ->schema([ |
||
| 123 | Toggle::make('analytics.enabled') |
||
| 124 | ->label('Enable Analytics') |
||
| 125 | ->default(true), |
||
| 126 | Toggle::make('analytics.track_opens') |
||
| 127 | ->label('Track Email Opens') |
||
| 128 | ->default(true) |
||
| 129 | ->visible(fn(Get $get): bool => $get('analytics.enabled')), |
||
| 130 | Toggle::make('analytics.track_clicks') |
||
| 131 | ->label('Track Link Clicks') |
||
| 132 | ->default(true) |
||
| 133 | ->visible(fn(Get $get): bool => $get('analytics.enabled')), |
||
| 134 | TextInput::make('analytics.retention_days') |
||
| 135 | ->label('Data Retention (Days)') |
||
| 136 | ->numeric() |
||
| 137 | ->default(90) |
||
| 138 | ->required() |
||
| 139 | ->visible(fn(Get $get): bool => $get('analytics.enabled')), |
||
| 140 | ]), |
||
| 141 | ]), |
||
| 142 | Tab::make('Rate Limiting') |
||
| 143 | ->icon('heroicon-o-clock') |
||
| 144 | ->schema([ |
||
| 145 | Section::make('Rate Limiting Settings') |
||
| 146 | ->description('Configure rate limits for notifications to prevent abuse') |
||
| 147 | ->schema([ |
||
| 148 | Toggle::make('rate_limiting.enabled') |
||
| 149 | ->label('Enable Rate Limiting') |
||
| 150 | ->default(true), |
||
| 151 | TextInput::make('rate_limiting.max_per_minute') |
||
| 152 | ->label('Max Per Minute') |
||
| 153 | ->numeric() |
||
| 154 | ->default(60) |
||
| 155 | ->required() |
||
| 156 | ->visible(fn(Get $get): bool => $get('rate_limiting.enabled')), |
||
| 157 | TextInput::make('rate_limiting.max_per_hour') |
||
| 158 | ->label('Max Per Hour') |
||
| 159 | ->numeric() |
||
| 160 | ->default(1000) |
||
| 161 | ->required() |
||
| 162 | ->visible(fn(Get $get): bool => $get('rate_limiting.enabled')), |
||
| 163 | TextInput::make('rate_limiting.max_per_day') |
||
| 164 | ->label('Max Per Day') |
||
| 165 | ->numeric() |
||
| 166 | ->default(10000) |
||
| 167 | ->required() |
||
| 168 | ->visible(fn(Get $get): bool => $get('rate_limiting.enabled')), |
||
| 169 | ]), |
||
| 170 | ]), |
||
| 171 | ]; |
||
| 172 | |||
| 173 | // Dynamically create tabs for each channel |
||
| 174 | foreach ($channels as $channel) { |
||
| 175 | $tabs[] = Tab::make($channel->title) |
||
| 176 | ->icon($channel->icon ?? 'heroicon-o-bell') |
||
| 177 | ->schema(self::getChannelSchema($channel)); |
||
| 178 | } |
||
| 179 | |||
| 180 | return $schema |
||
| 181 | ->schema([ |
||
| 182 | Tabs::make('Settings') |
||
| 183 | ->tabs($tabs) |
||
| 184 | ->columnSpanFull() |
||
| 185 | ]) |
||
| 186 | ->statePath('data'); |
||
| 187 | } |
||
| 347 |