EmailAddressProviderTrait   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A hasEmailAddress() 0 3 2
A getEmailAddress() 0 7 2
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