@@ -4,6 +4,6 @@ |
||
4 | 4 | |
5 | 5 | class ExpectingDTEXT extends InvalidEmail |
6 | 6 | { |
7 | - const CODE = 129; |
|
8 | - const REASON = "Expected DTEXT"; |
|
7 | + const CODE = 129; |
|
8 | + const REASON = "Expected DTEXT"; |
|
9 | 9 | } |
@@ -4,6 +4,6 @@ |
||
4 | 4 | |
5 | 5 | class ExpectingAT extends InvalidEmail |
6 | 6 | { |
7 | - const CODE = 202; |
|
8 | - const REASON = "Expecting AT '@' "; |
|
7 | + const CODE = 202; |
|
8 | + const REASON = "Expecting AT '@' "; |
|
9 | 9 | } |
@@ -4,6 +4,6 @@ |
||
4 | 4 | |
5 | 5 | class DotAtStart extends InvalidEmail |
6 | 6 | { |
7 | - const CODE = 141; |
|
8 | - const REASON = "Found DOT at start"; |
|
7 | + const CODE = 141; |
|
8 | + const REASON = "Found DOT at start"; |
|
9 | 9 | } |
@@ -4,6 +4,6 @@ |
||
4 | 4 | |
5 | 5 | class ConsecutiveDot extends InvalidEmail |
6 | 6 | { |
7 | - const CODE = 132; |
|
8 | - const REASON = "Consecutive DOT"; |
|
7 | + const CODE = 132; |
|
8 | + const REASON = "Consecutive DOT"; |
|
9 | 9 | } |
@@ -4,6 +4,6 @@ |
||
4 | 4 | |
5 | 5 | class AtextAfterCFWS extends InvalidEmail |
6 | 6 | { |
7 | - const CODE = 133; |
|
8 | - const REASON = "ATEXT found after CFWS"; |
|
7 | + const CODE = 133; |
|
8 | + const REASON = "ATEXT found after CFWS"; |
|
9 | 9 | } |
@@ -4,6 +4,6 @@ |
||
4 | 4 | |
5 | 5 | class DomainHyphened extends InvalidEmail |
6 | 6 | { |
7 | - const CODE = 144; |
|
8 | - const REASON = "Hyphen found in domain"; |
|
7 | + const CODE = 144; |
|
8 | + const REASON = "Hyphen found in domain"; |
|
9 | 9 | } |
@@ -4,6 +4,6 @@ |
||
4 | 4 | |
5 | 5 | class ExpectingCTEXT extends InvalidEmail |
6 | 6 | { |
7 | - const CODE = 139; |
|
8 | - const REASON = "Expecting CTEXT"; |
|
7 | + const CODE = 139; |
|
8 | + const REASON = "Expecting CTEXT"; |
|
9 | 9 | } |
@@ -4,6 +4,6 @@ |
||
4 | 4 | |
5 | 5 | class CharNotAllowed extends InvalidEmail |
6 | 6 | { |
7 | - const CODE = 201; |
|
8 | - const REASON = "Non allowed character in domain"; |
|
7 | + const CODE = 201; |
|
8 | + const REASON = "Non allowed character in domain"; |
|
9 | 9 | } |
@@ -7,118 +7,118 @@ |
||
7 | 7 | |
8 | 8 | class MultipleValidationWithAnd implements EmailValidation |
9 | 9 | { |
10 | - /** |
|
11 | - * If one of validations gets failure skips all succeeding validation. |
|
12 | - * This means MultipleErrors will only contain a single error which first found. |
|
13 | - */ |
|
14 | - const STOP_ON_ERROR = 0; |
|
15 | - |
|
16 | - /** |
|
17 | - * All of validations will be invoked even if one of them got failure. |
|
18 | - * So MultipleErrors will contain all causes. |
|
19 | - */ |
|
20 | - const ALLOW_ALL_ERRORS = 1; |
|
21 | - |
|
22 | - /** |
|
23 | - * @var EmailValidation[] |
|
24 | - */ |
|
25 | - private $validations = []; |
|
26 | - |
|
27 | - /** |
|
28 | - * @var array |
|
29 | - */ |
|
30 | - private $warnings = []; |
|
31 | - |
|
32 | - /** |
|
33 | - * @var MultipleErrors|null |
|
34 | - */ |
|
35 | - private $error; |
|
36 | - |
|
37 | - /** |
|
38 | - * @var int |
|
39 | - */ |
|
40 | - private $mode; |
|
41 | - |
|
42 | - /** |
|
43 | - * @param EmailValidation[] $validations The validations. |
|
44 | - * @param int $mode The validation mode (one of the constants). |
|
45 | - */ |
|
46 | - public function __construct(array $validations, $mode = self::ALLOW_ALL_ERRORS) |
|
47 | - { |
|
48 | - if (count($validations) == 0) { |
|
49 | - throw new EmptyValidationList(); |
|
50 | - } |
|
51 | - |
|
52 | - $this->validations = $validations; |
|
53 | - $this->mode = $mode; |
|
54 | - } |
|
55 | - |
|
56 | - /** |
|
57 | - * {@inheritdoc} |
|
58 | - */ |
|
59 | - public function isValid($email, EmailLexer $emailLexer) |
|
60 | - { |
|
61 | - $result = true; |
|
62 | - $errors = []; |
|
63 | - foreach ($this->validations as $validation) { |
|
64 | - $emailLexer->reset(); |
|
65 | - $validationResult = $validation->isValid($email, $emailLexer); |
|
66 | - $result = $result && $validationResult; |
|
67 | - $this->warnings = array_merge($this->warnings, $validation->getWarnings()); |
|
68 | - $errors = $this->addNewError($validation->getError(), $errors); |
|
69 | - |
|
70 | - if ($this->shouldStop($result)) { |
|
71 | - break; |
|
72 | - } |
|
73 | - } |
|
74 | - |
|
75 | - if (!empty($errors)) { |
|
76 | - $this->error = new MultipleErrors($errors); |
|
77 | - } |
|
78 | - |
|
79 | - return $result; |
|
80 | - } |
|
81 | - |
|
82 | - /** |
|
83 | - * @param \Egulias\EmailValidator\Exception\InvalidEmail|null $possibleError |
|
84 | - * @param \Egulias\EmailValidator\Exception\InvalidEmail[] $errors |
|
85 | - * |
|
86 | - * @return \Egulias\EmailValidator\Exception\InvalidEmail[] |
|
87 | - */ |
|
88 | - private function addNewError($possibleError, array $errors) |
|
89 | - { |
|
90 | - if (null !== $possibleError) { |
|
91 | - $errors[] = $possibleError; |
|
92 | - } |
|
93 | - |
|
94 | - return $errors; |
|
95 | - } |
|
96 | - |
|
97 | - /** |
|
98 | - * @param bool $result |
|
99 | - * |
|
100 | - * @return bool |
|
101 | - */ |
|
102 | - private function shouldStop($result) |
|
103 | - { |
|
104 | - return !$result && $this->mode === self::STOP_ON_ERROR; |
|
105 | - } |
|
106 | - |
|
107 | - /** |
|
108 | - * Returns the validation errors. |
|
109 | - * |
|
110 | - * @return MultipleErrors|null |
|
111 | - */ |
|
112 | - public function getError() |
|
113 | - { |
|
114 | - return $this->error; |
|
115 | - } |
|
116 | - |
|
117 | - /** |
|
118 | - * {@inheritdoc} |
|
119 | - */ |
|
120 | - public function getWarnings() |
|
121 | - { |
|
122 | - return $this->warnings; |
|
123 | - } |
|
10 | + /** |
|
11 | + * If one of validations gets failure skips all succeeding validation. |
|
12 | + * This means MultipleErrors will only contain a single error which first found. |
|
13 | + */ |
|
14 | + const STOP_ON_ERROR = 0; |
|
15 | + |
|
16 | + /** |
|
17 | + * All of validations will be invoked even if one of them got failure. |
|
18 | + * So MultipleErrors will contain all causes. |
|
19 | + */ |
|
20 | + const ALLOW_ALL_ERRORS = 1; |
|
21 | + |
|
22 | + /** |
|
23 | + * @var EmailValidation[] |
|
24 | + */ |
|
25 | + private $validations = []; |
|
26 | + |
|
27 | + /** |
|
28 | + * @var array |
|
29 | + */ |
|
30 | + private $warnings = []; |
|
31 | + |
|
32 | + /** |
|
33 | + * @var MultipleErrors|null |
|
34 | + */ |
|
35 | + private $error; |
|
36 | + |
|
37 | + /** |
|
38 | + * @var int |
|
39 | + */ |
|
40 | + private $mode; |
|
41 | + |
|
42 | + /** |
|
43 | + * @param EmailValidation[] $validations The validations. |
|
44 | + * @param int $mode The validation mode (one of the constants). |
|
45 | + */ |
|
46 | + public function __construct(array $validations, $mode = self::ALLOW_ALL_ERRORS) |
|
47 | + { |
|
48 | + if (count($validations) == 0) { |
|
49 | + throw new EmptyValidationList(); |
|
50 | + } |
|
51 | + |
|
52 | + $this->validations = $validations; |
|
53 | + $this->mode = $mode; |
|
54 | + } |
|
55 | + |
|
56 | + /** |
|
57 | + * {@inheritdoc} |
|
58 | + */ |
|
59 | + public function isValid($email, EmailLexer $emailLexer) |
|
60 | + { |
|
61 | + $result = true; |
|
62 | + $errors = []; |
|
63 | + foreach ($this->validations as $validation) { |
|
64 | + $emailLexer->reset(); |
|
65 | + $validationResult = $validation->isValid($email, $emailLexer); |
|
66 | + $result = $result && $validationResult; |
|
67 | + $this->warnings = array_merge($this->warnings, $validation->getWarnings()); |
|
68 | + $errors = $this->addNewError($validation->getError(), $errors); |
|
69 | + |
|
70 | + if ($this->shouldStop($result)) { |
|
71 | + break; |
|
72 | + } |
|
73 | + } |
|
74 | + |
|
75 | + if (!empty($errors)) { |
|
76 | + $this->error = new MultipleErrors($errors); |
|
77 | + } |
|
78 | + |
|
79 | + return $result; |
|
80 | + } |
|
81 | + |
|
82 | + /** |
|
83 | + * @param \Egulias\EmailValidator\Exception\InvalidEmail|null $possibleError |
|
84 | + * @param \Egulias\EmailValidator\Exception\InvalidEmail[] $errors |
|
85 | + * |
|
86 | + * @return \Egulias\EmailValidator\Exception\InvalidEmail[] |
|
87 | + */ |
|
88 | + private function addNewError($possibleError, array $errors) |
|
89 | + { |
|
90 | + if (null !== $possibleError) { |
|
91 | + $errors[] = $possibleError; |
|
92 | + } |
|
93 | + |
|
94 | + return $errors; |
|
95 | + } |
|
96 | + |
|
97 | + /** |
|
98 | + * @param bool $result |
|
99 | + * |
|
100 | + * @return bool |
|
101 | + */ |
|
102 | + private function shouldStop($result) |
|
103 | + { |
|
104 | + return !$result && $this->mode === self::STOP_ON_ERROR; |
|
105 | + } |
|
106 | + |
|
107 | + /** |
|
108 | + * Returns the validation errors. |
|
109 | + * |
|
110 | + * @return MultipleErrors|null |
|
111 | + */ |
|
112 | + public function getError() |
|
113 | + { |
|
114 | + return $this->error; |
|
115 | + } |
|
116 | + |
|
117 | + /** |
|
118 | + * {@inheritdoc} |
|
119 | + */ |
|
120 | + public function getWarnings() |
|
121 | + { |
|
122 | + return $this->warnings; |
|
123 | + } |
|
124 | 124 | } |