Policy   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 151
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 10
eloc 28
dl 0
loc 151
rs 10
c 3
b 0
f 0

10 Methods

Rating   Name   Duplication   Size   Complexity  
A checkDisposableLocalListOnly() 0 3 1
A checkBannedListedEmail() 0 3 1
A getBannedList() 0 3 1
A __construct() 0 12 1
A getDisposableList() 0 3 1
A checkFreeEmail() 0 3 1
A checkFreeLocalListOnly() 0 3 1
A getFreeList() 0 3 1
A checkDisposableEmail() 0 3 1
A validateMxRecord() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace EmailValidator;
6
7
class Policy
8
{
9
    /**
10
     * @var bool
11
     */
12
    private bool $checkBannedListedEmail;
13
14
    /**
15
     * @var bool
16
     */
17
    private bool $checkDisposableEmail;
18
19
    /**
20
     * @var bool
21
     */
22
    private bool $checkFreeEmail;
23
24
    /**
25
     * @var array<string>
26
     */
27
    private array $bannedList;
28
29
    /**
30
     * @var bool
31
     */
32
    private bool $checkMxRecords;
33
34
    /**
35
     * @var array<string>
36
     */
37
    private array $disposableList;
38
39
    /**
40
     * @var array<string>
41
     */
42
    private array $freeList;
43
44
    /**
45
     * @var bool
46
     */
47
    private bool $localDisposableOnly;
48
49
    /**
50
     * @var bool
51
     */
52
    private bool $localFreeOnly;
53
54
    public function __construct(array $config = [])
55
    {
56
        $this->checkMxRecords = (bool) ($config['checkMxRecords'] ?? true);
57
        $this->checkBannedListedEmail = (bool) ($config['checkBannedListedEmail'] ?? false);
58
        $this->checkDisposableEmail = (bool) ($config['checkDisposableEmail'] ?? false);
59
        $this->checkFreeEmail = (bool) ($config['checkFreeEmail'] ?? false);
60
        $this->localDisposableOnly = (bool) ($config['LocalDisposableOnly'] ?? false);
61
        $this->localFreeOnly = (bool) ($config['LocalFreeOnly'] ?? false);
62
63
        $this->bannedList = $config['bannedList'] ?? [];
64
        $this->disposableList = $config['disposableList'] ?? [];
65
        $this->freeList = $config['freeList'] ?? [];
66
    }
67
68
    /**
69
     * Validate MX records?
70
     *
71
     * @return bool
72
     */
73
    public function validateMxRecord(): bool
74
    {
75
        return $this->checkMxRecords;
76
    }
77
78
    /**
79
     * Check domain if it is on the banned list?
80
     *
81
     * @return bool
82
     */
83
    public function checkBannedListedEmail(): bool
84
    {
85
        return $this->checkBannedListedEmail;
86
    }
87
88
    /**
89
     * Check if the domain is used by a disposable email site?
90
     *
91
     * @return bool
92
     */
93
    public function checkDisposableEmail(): bool
94
    {
95
        return $this->checkDisposableEmail;
96
    }
97
98
    /**
99
     * Check if the domain is used by a free email site?
100
     *
101
     * @return bool
102
     */
103
    public function checkFreeEmail(): bool
104
    {
105
        return $this->checkFreeEmail;
106
    }
107
108
    /**
109
     * Check if only a local copy of disposable email address domains should be used. Saves the overhead of
110
     * making HTTP requests to get the list the first time that validation is called.
111
     *
112
     * @return bool
113
     */
114
    public function checkDisposableLocalListOnly(): bool
115
    {
116
        return $this->localDisposableOnly;
117
    }
118
119
    /**
120
     * Check if only a local copy of free email address domains should be used. Saves the overhead of
121
     * making HTTP requests to get the list the first time that validation is called.
122
     *
123
     * @return bool
124
     */
125
    public function checkFreeLocalListOnly(): bool
126
    {
127
        return $this->localFreeOnly;
128
    }
129
130
    /**
131
     * Returns the list of banned domains.
132
     *
133
     * @return array<string>
134
     */
135
    public function getBannedList(): array
136
    {
137
        return $this->bannedList;
138
    }
139
140
    /**
141
     * Returns the list of free email provider domains.
142
     *
143
     * @return array<string>
144
     */
145
    public function getFreeList(): array
146
    {
147
        return $this->freeList;
148
    }
149
150
    /**
151
     * Returns the list of disposable email domains.
152
     *
153
     * @return array<string>
154
     */
155
    public function getDisposableList(): array
156
    {
157
        return $this->disposableList;
158
    }
159
}
160