|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace App\Notifications; |
| 4 | + |
| 5 | +use App\Models\Plugin; |
| 6 | +use Illuminate\Bus\Queueable; |
| 7 | +use Illuminate\Contracts\Queue\ShouldQueue; |
| 8 | +use Illuminate\Notifications\Messages\MailMessage; |
| 9 | +use Illuminate\Notifications\Notification; |
| 10 | + |
| 11 | +class PluginReviewChecksIncomplete extends Notification implements ShouldQueue |
| 12 | +{ |
| 13 | + use Queueable; |
| 14 | + |
| 15 | + private const DOCS_BASE = 'https://nativephp.com/docs/mobile/3/plugins'; |
| 16 | + |
| 17 | + /** |
| 18 | + * @var array<string, array{label: string, passing_label: string, docs_url: string, docs_label: string}> |
| 19 | + */ |
| 20 | + private const CHECK_DEFINITIONS = [ |
| 21 | + 'supports_ios' => [ |
| 22 | + 'label' => 'iOS native code in `resources/ios/Sources/`', |
| 23 | + 'passing_label' => 'iOS native code', |
| 24 | + 'docs_url' => self::DOCS_BASE.'/bridge-functions', |
| 25 | + 'docs_label' => 'Bridge Functions guide', |
| 26 | + ], |
| 27 | + 'supports_android' => [ |
| 28 | + 'label' => 'Android native code in `resources/android/src/`', |
| 29 | + 'passing_label' => 'Android native code', |
| 30 | + 'docs_url' => self::DOCS_BASE.'/bridge-functions', |
| 31 | + 'docs_label' => 'Bridge Functions guide', |
| 32 | + ], |
| 33 | + 'supports_js' => [ |
| 34 | + 'label' => 'JavaScript library in `resources/js/`', |
| 35 | + 'passing_label' => 'JavaScript library', |
| 36 | + 'docs_url' => self::DOCS_BASE.'/creating-plugins', |
| 37 | + 'docs_label' => 'Creating Plugins guide', |
| 38 | + ], |
| 39 | + 'has_support_email' => [ |
| 40 | + 'label' => 'Support email in your README', |
| 41 | + 'passing_label' => 'Support email', |
| 42 | + 'docs_url' => self::DOCS_BASE.'/best-practices', |
| 43 | + 'docs_label' => 'Best Practices guide', |
| 44 | + ], |
| 45 | + 'requires_mobile_sdk' => [ |
| 46 | + 'label' => '`nativephp/mobile` required in `composer.json`', |
| 47 | + 'passing_label' => 'Requires nativephp/mobile', |
| 48 | + 'docs_url' => self::DOCS_BASE.'/creating-plugins', |
| 49 | + 'docs_label' => 'Creating Plugins guide', |
| 50 | + ], |
| 51 | + 'has_ios_min_version' => [ |
| 52 | + 'label' => 'iOS `min_version` set in `nativephp.json`', |
| 53 | + 'passing_label' => 'iOS min_version', |
| 54 | + 'docs_url' => self::DOCS_BASE.'/advanced-configuration', |
| 55 | + 'docs_label' => 'Advanced Configuration guide', |
| 56 | + ], |
| 57 | + 'has_android_min_version' => [ |
| 58 | + 'label' => 'Android `min_version` set in `nativephp.json`', |
| 59 | + 'passing_label' => 'Android min_version', |
| 60 | + 'docs_url' => self::DOCS_BASE.'/advanced-configuration', |
| 61 | + 'docs_label' => 'Advanced Configuration guide', |
| 62 | + ], |
| 63 | + ]; |
| 64 | + |
| 65 | + public function __construct(public Plugin $plugin) {} |
| 66 | + |
| 67 | + /** |
| 68 | + * @return array<int, string> |
| 69 | + */ |
| 70 | + public function via(object $notifiable): array |
| 71 | + { |
| 72 | + return ['mail']; |
| 73 | + } |
| 74 | + |
| 75 | + public function toMail(object $notifiable): MailMessage |
| 76 | + { |
| 77 | + $checks = $this->plugin->review_checks ?? []; |
| 78 | + $passing = $this->getPassingChecks($checks); |
| 79 | + $failing = $this->getFailingChecks($checks); |
| 80 | + |
| 81 | + $message = (new MailMessage) |
| 82 | + ->subject('Action Required: '.$this->plugin->name.' — Review Checks') |
| 83 | + ->greeting('Hello,') |
| 84 | + ->line("We've run automated checks against your plugin **{$this->plugin->name}** and found some items that need your attention before we can approve it."); |
| 85 | + |
| 86 | + if (count($passing) > 0) { |
| 87 | + $message->line('**Passing checks:**'); |
| 88 | + |
| 89 | + foreach ($passing as $item) { |
| 90 | + $message->line("✅ {$item}"); |
| 91 | + } |
| 92 | + } |
| 93 | + |
| 94 | + if (count($failing) > 0) { |
| 95 | + $message->line('**Missing items:**'); |
| 96 | + |
| 97 | + foreach ($failing as $item) { |
| 98 | + $message->line("❌ {$item['label']} — [{$item['docs_label']}]({$item['docs_url']})"); |
| 99 | + } |
| 100 | + } |
| 101 | + |
| 102 | + $message |
| 103 | + ->line('Please update your repository to address the missing items above. Once updated, we\'ll re-run the checks automatically.') |
| 104 | + ->action('View Best Practices', self::DOCS_BASE.'/best-practices') |
| 105 | + ->salutation("Happy coding!\n\nThe NativePHP Team"); |
| 106 | + |
| 107 | + return $message; |
| 108 | + } |
| 109 | + |
| 110 | + /** |
| 111 | + * @return array<string, mixed> |
| 112 | + */ |
| 113 | + public function toArray(object $notifiable): array |
| 114 | + { |
| 115 | + return [ |
| 116 | + 'plugin_id' => $this->plugin->id, |
| 117 | + 'plugin_name' => $this->plugin->name, |
| 118 | + ]; |
| 119 | + } |
| 120 | + |
| 121 | + /** |
| 122 | + * @return array<int, string> |
| 123 | + */ |
| 124 | + private function getPassingChecks(array $checks): array |
| 125 | + { |
| 126 | + $passing = []; |
| 127 | + |
| 128 | + foreach (self::CHECK_DEFINITIONS as $key => $definition) { |
| 129 | + if (! empty($checks[$key])) { |
| 130 | + $passing[] = $definition['passing_label']; |
| 131 | + } |
| 132 | + } |
| 133 | + |
| 134 | + return $passing; |
| 135 | + } |
| 136 | + |
| 137 | + /** |
| 138 | + * @return array<int, array{label: string, docs_url: string, docs_label: string}> |
| 139 | + */ |
| 140 | + private function getFailingChecks(array $checks): array |
| 141 | + { |
| 142 | + $failing = []; |
| 143 | + |
| 144 | + foreach (self::CHECK_DEFINITIONS as $key => $definition) { |
| 145 | + if (empty($checks[$key])) { |
| 146 | + $failing[] = [ |
| 147 | + 'label' => $definition['label'], |
| 148 | + 'docs_url' => $definition['docs_url'], |
| 149 | + 'docs_label' => $definition['docs_label'], |
| 150 | + ]; |
| 151 | + } |
| 152 | + } |
| 153 | + |
| 154 | + return $failing; |
| 155 | + } |
| 156 | +} |
0 commit comments