| 1 | <?php |
||
| 2 | |||
| 3 | namespace ag84ark\AwsSesBounceComplaintHandler; |
||
| 4 | |||
| 5 | use ag84ark\AwsSesBounceComplaintHandler\Models\WrongEmail; |
||
| 6 | use Illuminate\Support\Collection; |
||
| 7 | |||
| 8 | class AwsSesBounceComplaintHandler |
||
| 9 | { |
||
| 10 | 3 | public function canSendToEmail(string $email): bool |
|
| 11 | { |
||
| 12 | /** @var WrongEmail[]|Collection $emails */ |
||
| 13 | 3 | $emails = WrongEmail::active() |
|
| 14 | 3 | ->bounced() |
|
| 15 | 3 | ->where('email', '=', $email) |
|
| 16 | 3 | ->get(); |
|
| 17 | |||
| 18 | 3 | foreach ($emails as $wrongEmail) { |
|
| 19 | 2 | if (! $wrongEmail->canBouncedSend()) { |
|
| 20 | 2 | return false; |
|
| 21 | } |
||
| 22 | } |
||
| 23 | |||
| 24 | 2 | return true; |
|
| 25 | } |
||
| 26 | |||
| 27 | 1 | public function ignoreEmail(string $email): void |
|
| 28 | { |
||
| 29 | /** @var WrongEmail[]|Collection $emails */ |
||
| 30 | 1 | $emails = WrongEmail::where('email', '=', $email)->get(); |
|
| 31 | |||
| 32 | 1 | foreach ($emails as $wrongEmail) { |
|
| 33 | 1 | $wrongEmail->ignore = true; |
|
|
0 ignored issues
–
show
|
|||
| 34 | 1 | $wrongEmail->save(); |
|
| 35 | } |
||
| 36 | 1 | } |
|
| 37 | |||
| 38 | 1 | public function clearEmail(string $email): void |
|
| 39 | { |
||
| 40 | /* @var WrongEmail[]|Collection $emails */ |
||
| 41 | 1 | WrongEmail::where('email', '=', $email)->delete(); |
|
| 42 | 1 | } |
|
| 43 | } |
||
| 44 |
This check looks for assignments to scalar types that may be of the wrong type.
To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.