Passed
Push — message-id-validator ( 1cb5b2...07464f )
by Eduardo Gulias
02:11
created

MessageIDValidation   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 53.33%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 4
dl 0
loc 31
ccs 8
cts 15
cp 0.5333
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A isValid() 0 18 3
A getWarnings() 0 4 1
A getError() 0 4 1
1
<?php
2
3
namespace Egulias\EmailValidator\Validation;
4
5
use Egulias\EmailValidator\EmailLexer;
6
use Egulias\EmailValidator\MessageIDParser;
7
use Egulias\EmailValidator\Result\InvalidEmail;
8
use Egulias\EmailValidator\Result\Reason\ExceptionFound;
9
10
class MessageIDValidation implements EmailValidation
11
{
12 4
    public function isValid(string $email, EmailLexer $emailLexer): bool
13
    {
14 4
        $this->parser = new MessageIDParser($emailLexer);
0 ignored issues
show
Bug introduced by
The property parser does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
15
        try {
16 4
            $result = $this->parser->parse($email);
17 4
            $this->warnings = $this->parser->getWarnings();
0 ignored issues
show
Bug introduced by
The property warnings does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
18 4
            if ($result->isInvalid()) {
19
                /** @psalm-suppress PropertyTypeCoercion */
20 1
                $this->error = $result;
0 ignored issues
show
Bug introduced by
The property error does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
21 4
                return false;
22
            }
23
        } catch (\Exception $invalid) {
24
            $this->error = new InvalidEmail(new ExceptionFound($invalid), '');
25
            return false;
26
        }
27
28 3
        return true;
29
    }
30
31
    public function getWarnings(): array
32
    {
33
        return [];
34
    }
35
36
    public function getError(): ?InvalidEmail
37
    {
38
        return null;
39
    }
40
}
41