Email::getValue()   A
last analyzed

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 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace VasilDakov\Speedy\Model;
6
7
/**
8
 * Class Email.
9
 *
10
 * @author Vasil Dakov <[email protected]>
11
 * @copyright 2009-2022 Neutrino.bg
12
 *
13
 * @version 1.0
14
 */
15
class Email implements \JsonSerializable
16
{
17
    private string $value;
18
19 6
    public function __construct(string $value)
20
    {
21 6
        $this->setValue($value);
22
    }
23
24 1
    public function getValue(): string
25
    {
26 1
        return $this->value;
27
    }
28
29 6
    private function setValue(string $value): void
30
    {
31 6
        if (! \filter_var($value, \FILTER_VALIDATE_EMAIL)) {
32 1
            throw new \InvalidArgumentException();
33
        }
34 5
        $this->value = $value;
35
    }
36
37 1
    public function compareTo(self $other): int
38
    {
39 1
        return \strcasecmp($this->getValue(), $other->getValue());
40
    }
41
42 1
    public function equals(self $other): bool
43
    {
44 1
        return 0 === $this->compareTo($other);
45
    }
46
47 1
    final public function __toString(): string
48
    {
49 1
        return $this->value;
50
    }
51
52 1
    public function jsonSerialize(): string
53
    {
54 1
        return $this->value;
55
    }
56
57 1
    public function toArray(): array
58
    {
59 1
        return [];
60
    }
61
}
62