From::fromEmailAddress()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Genkgo\Mail\Header;
5
6
use Genkgo\Mail\Address;
7
use Genkgo\Mail\EmailAddress;
8
use Genkgo\Mail\HeaderInterface;
9
10
final class From implements HeaderInterface
11
{
12
    /**
13
     * @var Address
14
     */
15
    private $from;
16
17
    /**
18
     * @param Address $from
19
     */
20 19
    public function __construct(Address $from)
21
    {
22 19
        $this->from = $from;
23 19
    }
24
25
    /**
26
     * @return HeaderName
27
     */
28 16
    public function getName(): HeaderName
29
    {
30 16
        return new HeaderName('From');
31
    }
32
33
    /**
34
     * @return HeaderValue
35
     */
36 16
    public function getValue(): HeaderValue
37
    {
38 16
        return HeaderValue::fromEncodedString((string)$this->from);
39
    }
40
41
    /**
42
     * @param string $emailAddress
43
     * @param string $name
44
     * @return From
45
     */
46 1
    public static function fromAddress(string $emailAddress, string $name = ''): From
47
    {
48 1
        return new self(new Address(new EmailAddress($emailAddress), $name));
49
    }
50
51
    /**
52
     * @param string $emailAddress
53
     * @return From
54
     */
55 1
    public static function fromEmailAddress(string $emailAddress): From
56
    {
57 1
        return new self(new Address(new EmailAddress($emailAddress)));
58
    }
59
}
60