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

From::fromAddress()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

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
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 10
    public function __construct(Address $from)
22
    {
23 10
        $this->from = $from;
24 10
    }
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 10
    public function getValue(): HeaderValue
38
    {
39 10
        return new HeaderValue((string)$this->from);
40
    }
41
42
    /**
43
     * @param string $emailAddress
44
     * @param string $name
45
     * @return From
46
     */
47 1
    public static function fromAddress(string $emailAddress, string $name = ''): From
48
    {
49 1
        return new self(new Address(new EmailAddress($emailAddress), $name));
50
    }
51
52
    /**
53
     * @param string $emailAddress
54
     * @return From
55
     */
56 1
    public static function fromEmailAddress(string $emailAddress): From
57
    {
58 1
        return new self(new Address(new EmailAddress($emailAddress)));
59
    }
60
}