Email   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 14
dl 0
loc 54
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getMessage() 0 3 1
A validate() 0 5 1
A concreteValidate() 0 8 2
1
<?php
2
3
/**
4
 * Linna Filter
5
 *
6
 * @author Sebastian Rapetti <[email protected]>
7
 * @copyright (c) 2018, Sebastian Rapetti
8
 * @license http://opensource.org/licenses/MIT MIT License
9
 */
10
declare(strict_types=1);
11
12
namespace Linna\Filter\Rules;
13
14
/**
15
 * Check if provided email is valid.
16
 */
17
class Email implements RuleValidateInterface
18
{
19
    /**
20
     * @var array Rule properties
21
     */
22
    public static $config = [
23
        'full_class' => __CLASS__,
24
        'alias' => ['email', 'mail', 'e@'],
25
        'args_count' => 0,
26
        'args_type' => []
27
    ];
28
29
    /**
30
     * @var string Error message
31
     */
32
    private $message = '';
33
34
    /**
35
     * Validate.
36
     *
37
     * @return bool
38
     */
39 24
    public function validate(): bool
40
    {
41 24
        $args = \func_get_args();
42
43 24
        return $this->concreteValidate($args[0]);
44
    }
45
46
    /**
47
     * Concrete validate.
48
     *
49
     * @param string $received
50
     *
51
     * @return bool
52
     */
53 24
    private function concreteValidate(string $received): bool
54
    {
55 24
        if (!\filter_var($received, FILTER_VALIDATE_EMAIL)) {
56 18
            $this->message = "Received string is an invalid e-mail address";
57 18
            return true;
58
        }
59
60 6
        return false;
61
    }
62
63
    /**
64
     * Return error message.
65
     *
66
     * @return string Error message
67
     */
68 18
    public function getMessage(): string
69
    {
70 18
        return $this->message;
71
    }
72
}
73