Subversion-Projekte lars-tiefland.laravel_shop

Revision

Revision 148 | Ganze Datei anzeigen | Leerzeichen ignorieren | Details | Blame | Letzte Änderung | Log anzeigen | RSS feed

Revision 148 Revision 150
Zeile 1... Zeile 1...
1
<?php
1
<?php
-
 
2
 
2
namespace Egulias\EmailValidator\Parser;
3
namespace Egulias\EmailValidator\Parser;
Zeile 3... Zeile 4...
3
 
4
 
4
use Egulias\EmailValidator\EmailLexer;
5
use Egulias\EmailValidator\EmailLexer;
5
use Egulias\EmailValidator\Warning\CFWSNearAt;
6
use Egulias\EmailValidator\Warning\CFWSNearAt;
Zeile 21... Zeile 22...
21
        EmailLexer::S_CR,
22
        EmailLexer::S_CR,
22
        EmailLexer::S_LF,
23
        EmailLexer::S_LF,
23
        EmailLexer::CRLF
24
        EmailLexer::CRLF
24
    ];
25
    ];
Zeile 25... Zeile 26...
25
 
26
 
26
    public function parse() : Result
27
    public function parse(): Result
27
    {
28
    {
28
        if (!$this->isFWS()) {
29
        if (!$this->isFWS()) {
29
            return new ValidEmail();
30
            return new ValidEmail();
Zeile 34... Zeile 35...
34
        $resultCRLF = $this->checkCRLFInFWS();
35
        $resultCRLF = $this->checkCRLFInFWS();
35
        if ($resultCRLF->isInvalid()) {
36
        if ($resultCRLF->isInvalid()) {
36
            return $resultCRLF;
37
            return $resultCRLF;
37
        }
38
        }
Zeile 38... Zeile 39...
38
 
39
 
39
        if ($this->lexer->token['type'] === EmailLexer::S_CR) {
40
        if ($this->lexer->current->isA(EmailLexer::S_CR)) {
40
            return new InvalidEmail(new CRNoLF(), $this->lexer->token['value']);
41
            return new InvalidEmail(new CRNoLF(), $this->lexer->current->value);
Zeile 41... Zeile 42...
41
        }
42
        }
42
 
43
 
43
        if ($this->lexer->isNextToken(EmailLexer::GENERIC) && $previous['type']  !== EmailLexer::S_AT) {
44
        if ($this->lexer->isNextToken(EmailLexer::GENERIC) && !$previous->isA(EmailLexer::S_AT)) {
Zeile 44... Zeile 45...
44
            return new InvalidEmail(new AtextAfterCFWS(), $this->lexer->token['value']);
45
            return new InvalidEmail(new AtextAfterCFWS(), $this->lexer->current->value);
45
        }
46
        }
46
 
47
 
Zeile 47... Zeile 48...
47
        if ($this->lexer->token['type'] === EmailLexer::S_LF || $this->lexer->token['type'] === EmailLexer::C_NUL) {
48
        if ($this->lexer->current->isA(EmailLexer::S_LF) || $this->lexer->current->isA(EmailLexer::C_NUL)) {
48
            return new InvalidEmail(new ExpectingCTEXT(), $this->lexer->token['value']);
49
            return new InvalidEmail(new ExpectingCTEXT(), $this->lexer->current->value);
49
        }
50
        }
50
 
51
 
51
        if ($this->lexer->isNextToken(EmailLexer::S_AT) || $previous['type']  === EmailLexer::S_AT) {
52
        if ($this->lexer->isNextToken(EmailLexer::S_AT) || $previous->isA(EmailLexer::S_AT)) {
Zeile 52... Zeile 53...
52
            $this->warnings[CFWSNearAt::CODE] = new CFWSNearAt();
53
            $this->warnings[CFWSNearAt::CODE] = new CFWSNearAt();
53
        } else {
54
        } else {
Zeile 54... Zeile 55...
54
            $this->warnings[CFWSWithFWS::CODE] = new CFWSWithFWS();
55
            $this->warnings[CFWSWithFWS::CODE] = new CFWSWithFWS();
55
        }
56
        }
56
 
57
 
57
        return new ValidEmail();
58
        return new ValidEmail();
58
    }
59
    }
Zeile 59... Zeile 60...
59
 
60
 
60
    protected function checkCRLFInFWS() : Result
61
    protected function checkCRLFInFWS(): Result
61
    {
62
    {
Zeile 62... Zeile 63...
62
        if ($this->lexer->token['type'] !== EmailLexer::CRLF) {
63
        if (!$this->lexer->current->isA(EmailLexer::CRLF)) {
63
            return new ValidEmail();
64
            return new ValidEmail();
64
        }
65
        }
65
 
66
 
Zeile 66... Zeile 67...
66
        if (!$this->lexer->isNextTokenAny(array(EmailLexer::S_SP, EmailLexer::S_HTAB))) {
67
        if (!$this->lexer->isNextTokenAny(array(EmailLexer::S_SP, EmailLexer::S_HTAB))) {
67
            return new InvalidEmail(new CRLFX2(), $this->lexer->token['value']);
68
            return new InvalidEmail(new CRLFX2(), $this->lexer->current->value);
68
        }
69
        }
69
 
70
 
70
        //this has no coverage. Condition is repeated from above one
71
        //this has no coverage. Condition is repeated from above one
71
        if (!$this->lexer->isNextTokenAny(array(EmailLexer::S_SP, EmailLexer::S_HTAB))) {
72
        if (!$this->lexer->isNextTokenAny(array(EmailLexer::S_SP, EmailLexer::S_HTAB))) {
72
            return new InvalidEmail(new CRLFAtTheEnd(), $this->lexer->token['value']);
73
            return new InvalidEmail(new CRLFAtTheEnd(), $this->lexer->current->value);
73
        }
74
        }
Zeile 74... Zeile 75...
74
 
75
 
75
        return new ValidEmail();
76
        return new ValidEmail();
76
    }
77
    }