EmailAddressProviderTrait::getEmailAddress()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 0
dl 0
loc 7
ccs 4
cts 4
cp 1
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Nordic\EmailAddress;
6
7
/**
8
 * Email address provider trait
9
 *
10
 * @implements EmailAddressProviderInterface
11
 */
12
trait EmailAddressProviderTrait
13
{
14
    /**
15
     * @var EmailAddressInterface
16
     */
17
    protected $emailAddress;
18
19
    /**
20
     * @inheritDoc
21
     */
22 12
    public function getEmailAddress(): EmailAddressInterface
23
    {
24 12
        if (!$this->hasEmailAddress()) {
25 9
            $this->emailAddress = new NullEmailAddress;
26
        }
27
28 12
        return $this->emailAddress;
29
    }
30
31
    /**
32
     * @inheritDoc
33
     */
34 12
    public function hasEmailAddress(): bool
35
    {
36 12
        return $this->emailAddress instanceof EmailAddressInterface && !$this->emailAddress instanceof NullEmailAddress;
37
    }
38
}
39