WrongEmail::canBouncedSend()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 3
c 1
b 0
f 0
nc 3
nop 0
dl 0
loc 5
ccs 4
cts 4
cp 1
crap 3
rs 10
1
<?php
2
3
namespace ag84ark\AwsSesBounceComplaintHandler\Models;
4
5
use Illuminate\Database\Eloquent\Builder;
6
use Illuminate\Database\Eloquent\Model;
7
8
/**
9
 * ag84ark\AwsSesBounceComplaintHandler\Models\WrongEmail.
10
 *
11
 * @property int                             $id
12
 * @property string                          $email
13
 * @property string                          $problem_type
14
 * @property string                          $problem_subtype
15
 * @property int                             $repeated_attempts
16
 * @property int                             $ignore
17
 * @property \Illuminate\Support\Carbon|null $created_at
18
 * @property \Illuminate\Support\Carbon|null $updated_at
19
 *
20
 * @method static \Illuminate\Database\Eloquent\Builder|\ag84ark\AwsSesBounceComplaintHandler\Models\WrongEmail active()
21
 * @method static \Illuminate\Database\Eloquent\Builder|\ag84ark\AwsSesBounceComplaintHandler\Models\WrongEmail bounced()
22
 * @method static \Illuminate\Database\Eloquent\Builder|\ag84ark\AwsSesBounceComplaintHandler\Models\WrongEmail complained()
23
 * @method static \Illuminate\Database\Eloquent\Builder|\ag84ark\AwsSesBounceComplaintHandler\Models\WrongEmail newModelQuery()
24
 * @method static \Illuminate\Database\Eloquent\Builder|\ag84ark\AwsSesBounceComplaintHandler\Models\WrongEmail newQuery()
25
 * @method static \Illuminate\Database\Eloquent\Builder|\ag84ark\AwsSesBounceComplaintHandler\Models\WrongEmail query()
26
 * @method static \Illuminate\Database\Eloquent\Builder|\ag84ark\AwsSesBounceComplaintHandler\Models\WrongEmail whereCreatedAt($value)
27
 * @method static \Illuminate\Database\Eloquent\Builder|\ag84ark\AwsSesBounceComplaintHandler\Models\WrongEmail whereEmail($value)
28
 * @method static \Illuminate\Database\Eloquent\Builder|\ag84ark\AwsSesBounceComplaintHandler\Models\WrongEmail whereId($value)
29
 * @method static \Illuminate\Database\Eloquent\Builder|\ag84ark\AwsSesBounceComplaintHandler\Models\WrongEmail whereIgnore($value)
30
 * @method static \Illuminate\Database\Eloquent\Builder|\ag84ark\AwsSesBounceComplaintHandler\Models\WrongEmail whereProblemSubtype($value)
31
 * @method static \Illuminate\Database\Eloquent\Builder|\ag84ark\AwsSesBounceComplaintHandler\Models\WrongEmail whereProblemType($value)
32
 * @method static \Illuminate\Database\Eloquent\Builder|\ag84ark\AwsSesBounceComplaintHandler\Models\WrongEmail whereRepeatedAttempts($value)
33
 * @method static \Illuminate\Database\Eloquent\Builder|\ag84ark\AwsSesBounceComplaintHandler\Models\WrongEmail whereUpdatedAt($value)
34
 * @mixin \Eloquent
35
 */
36
class WrongEmail extends Model
37
{
38
    protected $table = 'wrong_emails';
39
40
    protected $fillable = ['email', 'problem_type', 'problem_subtype', 'repeated_attempts'];
41
42 1
    public function unsubscribed(): bool
43
    {
44 1
        return 'Complaint' === $this->problem_type;
45
    }
46
47 1
    public function dontSend(): bool
48
    {
49 1
        return ('Bounce' === $this->problem_type && 'Permanent' === $this->problem_subtype) || 'Complaint' === $this->problem_type;
50
    }
51
52 2
    public function canBouncedSend(): bool
53
    {
54 2
        return 'Bounce' === $this->problem_type
55 2
            && 'Permanent' !== $this->problem_subtype
56 2
            && $this->updated_at->diffInMinutes(config('aws-ses-bounce-complaint-handler.block_bounced_transient_for_minutes'));
0 ignored issues
show
introduced by
The method diffInMinutes() does not exist on DateTime. Are you sure you never get this type here, but always one of the subclasses? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

56
            && $this->updated_at->/** @scrutinizer ignore-call */ diffInMinutes(config('aws-ses-bounce-complaint-handler.block_bounced_transient_for_minutes'));
Loading history...
57
    }
58
59
    /**
60
     * Scope a query to only include popular users.
61
     *
62
     * @param Builder $query
63
     */
64 3
    public function scopeBounced($query): Builder
65
    {
66 3
        return $query->where('problem_type', '=', 'Bounce');
67
    }
68
69
    /**
70
     * Scope a query to only include popular users.
71
     *
72
     * @param Builder $query
73
     */
74 1
    public function scopeComplained($query): Builder
75
    {
76 1
        return $query->where('problem_type', '=', 'Complaint');
77
    }
78
79 3
    public function scopeActive(Builder $query): Builder
80
    {
81 3
        return $query->where('ignore', '=', false);
82
    }
83
}
84