Completed
Pull Request — master (#26)
by Ryosuke
01:50
created

From::fromAddress()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 1
cts 1
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 2
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
     * From constructor.
19
     * @param Address $from
20
     */
21 9
    public function __construct(Address $from)
22
    {
23 9
        $this->from = $from;
24 9
    }
25
26
    /**
27
     * @return HeaderName
28
     */
29 8
    public function getName(): HeaderName
30
    {
31 8
        return new HeaderName('From');
32
    }
33
34
    /**
35
     * @return HeaderValue
36
     */
37 9
    public function getValue(): HeaderValue
38
    {
39 9
        return new HeaderValue((string)$this->from);
40
    }
41
42
    /**
43
     * @param string $emailAddress
44
     * @param string $name
45
     * @return From
46 1
     */
47
    public static function fromAddress(string $emailAddress, string $name = ''): From
48 1
    {
49
        return new self(new Address(new EmailAddress($emailAddress), $name));
50
    }
51
52
    /**
53
     * @param string $emailAddress
54
     * @return From
55
     */
56
    public static function fromEmailAddress(string $emailAddress): From
57
    {
58
        return new self(new Address(new EmailAddress($emailAddress)));
59
    }
60
}