EmailAddress::__construct()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 4

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 12
ccs 8
cts 8
cp 1
rs 9.2
cc 4
eloc 7
nc 3
nop 2
crap 4
1
<?php
2
3
namespace Equip\ValueObject;
4
5
use InvalidArgumentException;
6
7
class EmailAddress
8
{
9
    /**
10
     * @var string|null
11
     */
12
    private $email;
13
14 6
    public function __construct($email, $is_required = true)
15
    {
16 6
        static $empty_values = [null, ''];
17
18 6
        if (!$is_required && in_array($email, $empty_values, true)) {
19 1
            $email = null;
20 6
        } elseif (filter_var($email, \FILTER_VALIDATE_EMAIL) === false) {
21 4
            throw new InvalidArgumentException('Value must be an email address');
22
        }
23
24 2
        $this->email = $email;
25 2
    }
26
27 2
    public function value()
28
    {
29 2
        return $this->email;
30
    }
31
}
32