| Conditions | 9 |
| Paths | 1 |
| Total Lines | 101 |
| Code Lines | 89 |
| 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 |
||
| 189 | protected static function getChannelSchema(NotificationChannel $channel): array |
||
| 190 | { |
||
| 191 | $schema = [ |
||
| 192 | Toggle::make("channels.{$channel->type}.enabled") |
||
| 193 | ->label("Enable {$channel->title}"), |
||
| 194 | ]; |
||
| 195 | |||
| 196 | $fields = match ($channel->type) { |
||
| 197 | 'email' => [ |
||
| 198 | TextInput::make("channels.{$channel->type}.from_address") |
||
| 199 | ->label('From Address') |
||
| 200 | ->email() |
||
| 201 | ->required() |
||
| 202 | ->visible(fn(Get $get): bool => $get("channels.{$channel->type}.enabled")), |
||
| 203 | TextInput::make("channels.{$channel->type}.from_name") |
||
| 204 | ->label('From Name') |
||
| 205 | ->required() |
||
| 206 | ->visible(fn(Get $get): bool => $get("channels.{$channel->type}.enabled")), |
||
| 207 | ], |
||
| 208 | 'slack' => [ |
||
| 209 | TextInput::make("channels.{$channel->type}.webhook_url") |
||
| 210 | ->label('Webhook URL') |
||
| 211 | ->url() |
||
| 212 | ->required() |
||
| 213 | ->visible(fn(Get $get): bool => $get("channels.{$channel->type}.enabled")), |
||
| 214 | TextInput::make("channels.{$channel->type}.channel") |
||
| 215 | ->label('Slack Channel') |
||
| 216 | ->default('#notifications') |
||
| 217 | ->visible(fn(Get $get): bool => $get("channels.{$channel->type}.enabled")), |
||
| 218 | TextInput::make("channels.{$channel->type}.username") |
||
| 219 | ->label('Bot Username') |
||
| 220 | ->default('Notification Bot') |
||
| 221 | ->visible(fn(Get $get): bool => $get("channels.{$channel->type}.enabled")), |
||
| 222 | ], |
||
| 223 | 'sms' => [ |
||
| 224 | Select::make("channels.{$channel->type}.provider") |
||
| 225 | ->label('SMS Provider') |
||
| 226 | ->options([ |
||
| 227 | 'twilio' => 'Twilio', |
||
| 228 | 'vonage' => 'Vonage (Nexmo)', |
||
| 229 | 'generic' => 'Generic API', |
||
| 230 | ]) |
||
| 231 | ->required() |
||
| 232 | ->visible(fn(Get $get): bool => $get("channels.{$channel->type}.enabled")), |
||
| 233 | TextInput::make("channels.{$channel->type}.twilio_account_sid") |
||
| 234 | ->label('Twilio Account SID') |
||
| 235 | ->visible(fn(Get $get): bool => $get("channels.{$channel->type}.enabled") && $get("channels.{$channel->type}.provider") === 'twilio'), |
||
| 236 | TextInput::make("channels.{$channel->type}.twilio_auth_token") |
||
| 237 | ->label('Twilio Auth Token') |
||
| 238 | ->password() |
||
| 239 | ->visible(fn(Get $get): bool => $get("channels.{$channel->type}.enabled") && $get("channels.{$channel->type}.provider") === 'twilio'), |
||
| 240 | TextInput::make("channels.{$channel->type}.twilio_phone_number") |
||
| 241 | ->label('Twilio Phone Number') |
||
| 242 | ->visible(fn(Get $get): bool => $get("channels.{$channel->type}.enabled") && $get("channels.{$channel->type}.provider") === 'twilio'), |
||
| 243 | TextInput::make("channels.{$channel->type}.api_url") |
||
| 244 | ->label('API URL') |
||
| 245 | ->url() |
||
| 246 | ->visible(fn(Get $get): bool => $get("channels.{$channel->type}.enabled") && $get("channels.{$channel->type}.provider") === 'generic'), |
||
| 247 | TextInput::make("channels.{$channel->type}.api_key") |
||
| 248 | ->label('API Key') |
||
| 249 | ->visible(fn(Get $get): bool => $get("channels.{$channel->type}.enabled") && ($get("channels.{$channel->type}.provider") === 'generic' || $get("channels.{$channel->type}.provider") === 'vonage')), |
||
| 250 | TextInput::make("channels.{$channel->type}.api_secret") |
||
| 251 | ->label('API Secret') |
||
| 252 | ->password() |
||
| 253 | ->visible(fn(Get $get): bool => $get("channels.{$channel->type}.enabled") && ($get("channels.{$channel->type}.provider") === 'generic' || $get("channels.{$channel->type}.provider") === 'vonage')), |
||
| 254 | ], |
||
| 255 | 'push' => [ |
||
| 256 | TextInput::make("channels.{$channel->type}.firebase_server_key") |
||
| 257 | ->label('Firebase Server Key') |
||
| 258 | ->password() |
||
| 259 | ->visible(fn(Get $get): bool => $get("channels.{$channel->type}.enabled")), |
||
| 260 | TextInput::make("channels.{$channel->type}.firebase_project_id") |
||
| 261 | ->label('Firebase Project ID') |
||
| 262 | ->visible(fn(Get $get): bool => $get("channels.{$channel->type}.enabled")), |
||
| 263 | ], |
||
| 264 | 'discord' => [ |
||
| 265 | TextInput::make("channels.{$channel->type}.webhook_url") |
||
| 266 | ->label('Discord Webhook URL') |
||
| 267 | ->url() |
||
| 268 | ->required() |
||
| 269 | ->helperText('Get this from your Discord server settings > Integrations > Webhooks') |
||
| 270 | ->visible(fn(Get $get): bool => $get("channels.{$channel->type}.enabled")), |
||
| 271 | TextInput::make("channels.{$channel->type}.username") |
||
| 272 | ->label('Bot Username') |
||
| 273 | ->helperText('Optional: Custom username for the webhook') |
||
| 274 | ->visible(fn(Get $get): bool => $get("channels.{$channel->type}.enabled")), |
||
| 275 | TextInput::make("channels.{$channel->type}.avatar_url") |
||
| 276 | ->label('Avatar URL') |
||
| 277 | ->url() |
||
| 278 | ->helperText('Optional: URL for the webhook avatar') |
||
| 279 | ->visible(fn(Get $get): bool => $get("channels.{$channel->type}.enabled")), |
||
| 280 | TextInput::make("channels.{$channel->type}.color") |
||
| 281 | ->label('Embed Color') |
||
| 282 | ->helperText('Optional: Decimal color code for embed (e.g., 3447003 for blue)') |
||
| 283 | ->numeric() |
||
| 284 | ->visible(fn(Get $get): bool => $get("channels.{$channel->type}.enabled")), |
||
| 285 | ], |
||
| 286 | default => [], |
||
| 287 | }; |
||
| 288 | |||
| 289 | return array_merge($schema, $fields); |
||
| 290 | } |
||
| 347 |