Completed
Push — master ( eaf770...e2d746 )
by Sebastian
04:09
created

Email::getMessage()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
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 RuleInterface
18
{
19
    /**
20
     * @var array Arguments expected.
21
     */
22
    private $arguments = [];
0 ignored issues
show
introduced by
The private property $arguments is not used, and could be removed.
Loading history...
23
24
    /**
25
     * @var string Error message
26
     */
27
    private $message = '';
28
29
    /**
30
     * Validate.
31
     *
32
     * @param string $received
33
     *
34
     * @return bool
35
     */
36 24
    public function validate(string $received): bool
37
    {
38 24
        if (!filter_var($received, FILTER_VALIDATE_EMAIL)) {
39 18
            $this->message = "Received string is an invalid e-mail address";
40 18
            return true;
41
        }
42
43 6
        return false;
44
    }
45
46
    /**
47
     * Return error message.
48
     *
49
     * @return string Error message
50
     */
51 18
    public function getMessage(): string
52
    {
53 18
        return $this->message;
54
    }
55
}
56