1 | <?php |
||||
2 | |||||
3 | namespace Egulias\EmailValidator\Parser; |
||||
4 | |||||
5 | use Egulias\EmailValidator\EmailLexer; |
||||
6 | use Egulias\EmailValidator\Result\InvalidEmail; |
||||
7 | use Egulias\EmailValidator\Result\Reason\ConsecutiveDot; |
||||
8 | use Egulias\EmailValidator\Result\Result; |
||||
9 | use Egulias\EmailValidator\Result\ValidEmail; |
||||
10 | use Egulias\EmailValidator\Warning\Warning; |
||||
11 | |||||
12 | abstract class PartParser |
||||
13 | { |
||||
14 | /** |
||||
15 | * @var Warning[] |
||||
16 | */ |
||||
17 | protected $warnings = []; |
||||
18 | |||||
19 | /** |
||||
20 | * @var EmailLexer |
||||
21 | */ |
||||
22 | protected $lexer; |
||||
23 | 186 | ||||
24 | public function __construct(EmailLexer $lexer) |
||||
25 | 186 | { |
|||
26 | $this->lexer = $lexer; |
||||
27 | } |
||||
28 | |||||
29 | abstract public function parse(): Result; |
||||
30 | |||||
31 | /** |
||||
32 | * @return Warning[] |
||||
33 | 186 | */ |
|||
34 | public function getWarnings() |
||||
35 | 186 | { |
|||
36 | return $this->warnings; |
||||
37 | } |
||||
38 | 114 | ||||
39 | protected function parseFWS(): Result |
||||
40 | 114 | { |
|||
41 | 114 | $foldingWS = new FoldingWhiteSpace($this->lexer); |
|||
42 | 114 | $resultFWS = $foldingWS->parse(); |
|||
43 | 114 | $this->warnings = array_merge($this->warnings, $foldingWS->getWarnings()); |
|||
44 | return $resultFWS; |
||||
45 | } |
||||
46 | 132 | ||||
47 | protected function checkConsecutiveDots(): Result |
||||
48 | 132 | { |
|||
49 | 2 | if ($this->lexer->current->isA(EmailLexer::S_DOT) && $this->lexer->isNextToken(EmailLexer::S_DOT)) { |
|||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||||
50 | return new InvalidEmail(new ConsecutiveDot(), $this->lexer->current->value); |
||||
51 | } |
||||
52 | 132 | ||||
53 | return new ValidEmail(); |
||||
54 | } |
||||
55 | 174 | ||||
56 | protected function escaped(): bool |
||||
57 | 174 | { |
|||
58 | $previous = $this->lexer->getPrevious(); |
||||
59 | 174 | ||||
60 | 174 | return $previous->isA(EmailLexer::S_BACKSLASH) |
|||
0 ignored issues
–
show
Egulias\EmailValidator\EmailLexer::S_BACKSLASH of type integer is incompatible with the type Doctrine\Common\Lexer\T expected by parameter $types of Doctrine\Common\Lexer\Token::isA() .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
61 | 174 | && !$this->lexer->current->isA(EmailLexer::GENERIC); |
|||
62 | } |
||||
63 | } |
||||
64 |