AwsSesBounceComplaintHandler::canSendToEmail()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 8
c 1
b 0
f 0
nc 3
nop 1
dl 0
loc 15
ccs 9
cts 9
cp 1
crap 3
rs 10
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
Documentation Bug introduced by
The property $ignore was declared of type integer, but true is of type true. Maybe add a type cast?

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.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
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