Test Setup Failed
Push — 3.0.0-dev ( 61798f...c8e7f0 )
by Eduardo Gulias
01:58
created

DomainComment   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 27
Duplicated Lines 11.11 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 4
dl 3
loc 27
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A exitCondition() 0 8 3
A endOfLoopValidations() 3 10 2
A getWarnings() 0 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Egulias\EmailValidator\Parser;
4
5
use Egulias\EmailValidator\EmailLexer;
6
use Egulias\EmailValidator\Result\Result;
7
use Egulias\EmailValidator\Result\ValidEmail;
8
use Egulias\EmailValidator\Result\InvalidEmail;
9
use Egulias\EmailValidator\Result\Reason\ExpectingATEXT;
10
11
class DomainComment implements CommentStrategy
12
{
13
    public function exitCondition(EmailLexer $lexer, int $openedParenthesis) : bool
14
    {
15
        if (($openedParenthesis === 0 && $lexer->isNextToken(EmailLexer::S_DOT))){ // || !$internalLexer->moveNext()) {
16
            return false;
17
        }
18
19
        return true;
20
    }
21
22
    public function endOfLoopValidations(EmailLexer $lexer) : Result
23
    {
24
        //test for end of string
25 View Code Duplication
        if (!$lexer->isNextToken(EmailLexer::S_DOT)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
26
            return new InvalidEmail(new ExpectingATEXT('DOT not found near CLOSEPARENTHESIS'), $lexer->token['value']);
27
        }
28
            //add warning
29
            //Address is valid within the message but cannot be used unmodified for the envelope
30
        return new ValidEmail();
31
    }
32
33
    public function getWarnings(): array
34
    {
35
        return [];
36
    }
37
}