| Conditions | 4 |
| Paths | 8 |
| Total Lines | 92 |
| Code Lines | 55 |
| 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 |
||
| 36 | private function createSampleData() |
||
| 37 | { |
||
| 38 | $this->info('Creating sample data...'); |
||
| 39 | |||
| 40 | // Create sample channels |
||
| 41 | $channels = [ |
||
| 42 | [ |
||
| 43 | 'title' => 'Email Notifications', |
||
| 44 | 'type' => 'email', |
||
| 45 | 'icon' => 'heroicon-o-envelope', |
||
| 46 | 'is_active' => true, |
||
| 47 | 'settings' => [ |
||
| 48 | 'smtp_host' => 'smtp.mailtrap.io', |
||
| 49 | 'smtp_port' => 2525, |
||
| 50 | ], |
||
| 51 | ], |
||
| 52 | [ |
||
| 53 | 'title' => 'Slack Notifications', |
||
| 54 | 'type' => 'slack', |
||
| 55 | 'icon' => 'heroicon-o-chat-bubble-left-right', |
||
| 56 | 'is_active' => true, |
||
| 57 | 'settings' => [ |
||
| 58 | 'webhook_url' => env('SLACK_WEBHOOK_URL', ''), |
||
| 59 | ], |
||
| 60 | ], |
||
| 61 | ]; |
||
| 62 | |||
| 63 | foreach ($channels as $channelData) { |
||
| 64 | \Usamamuneerchaudhary\Notifier\Models\NotificationChannel::firstOrCreate( |
||
| 65 | ['type' => $channelData['type']], |
||
| 66 | $channelData |
||
| 67 | ); |
||
| 68 | } |
||
| 69 | |||
| 70 | // Create sample events first |
||
| 71 | $events = [ |
||
| 72 | [ |
||
| 73 | 'group' => 'User Management', |
||
| 74 | 'name' => 'User Registered', |
||
| 75 | 'key' => 'user.registered', |
||
| 76 | 'description' => 'Triggered when a new user registers', |
||
| 77 | 'is_active' => true, |
||
| 78 | ], |
||
| 79 | [ |
||
| 80 | 'group' => 'User Management', |
||
| 81 | 'name' => 'Password Reset Requested', |
||
| 82 | 'key' => 'password.reset', |
||
| 83 | 'description' => 'Triggered when a user requests password reset', |
||
| 84 | 'is_active' => true, |
||
| 85 | ], |
||
| 86 | ]; |
||
| 87 | |||
| 88 | foreach ($events as $eventData) { |
||
| 89 | \Usamamuneerchaudhary\Notifier\Models\NotificationEvent::firstOrCreate( |
||
| 90 | ['key' => $eventData['key']], |
||
| 91 | $eventData |
||
| 92 | ); |
||
| 93 | } |
||
| 94 | |||
| 95 | // Create sample templates |
||
| 96 | $templates = [ |
||
| 97 | [ |
||
| 98 | 'name' => 'Welcome Email', |
||
| 99 | 'event_key' => 'user.registered', |
||
| 100 | 'subject' => 'Welcome to {{app_name}}, {{name}}!', |
||
| 101 | 'content' => "Hi {{name}},\n\nWelcome to {{app_name}}! We're excited to have you on board.\n\nBest regards,\nThe {{app_name}} Team", |
||
| 102 | 'variables' => [ |
||
| 103 | 'name' => 'User\'s full name', |
||
| 104 | 'app_name' => 'Application name', |
||
| 105 | ], |
||
| 106 | ], |
||
| 107 | [ |
||
| 108 | 'name' => 'Password Reset', |
||
| 109 | 'event_key' => 'password.reset', |
||
| 110 | 'subject' => 'Reset Your Password', |
||
| 111 | 'content' => "Hi {{name}},\n\nYou requested a password reset. Click the link below to reset your password:\n\n{{reset_link}}\n\nIf you didn't request this, please ignore this email.\n\nBest regards,\nThe {{app_name}} Team", |
||
| 112 | 'variables' => [ |
||
| 113 | 'name' => 'User\'s full name', |
||
| 114 | 'reset_link' => 'Password reset link', |
||
| 115 | 'app_name' => 'Application name', |
||
| 116 | ], |
||
| 117 | ], |
||
| 118 | ]; |
||
| 119 | |||
| 120 | foreach ($templates as $templateData) { |
||
| 121 | \Usamamuneerchaudhary\Notifier\Models\NotificationTemplate::firstOrCreate( |
||
| 122 | ['name' => $templateData['name'], 'event_key' => $templateData['event_key']], |
||
| 123 | $templateData |
||
| 124 | ); |
||
| 125 | } |
||
| 126 | |||
| 127 | $this->info('Sample data created successfully!'); |
||
| 128 | } |
||
| 130 |