EmailHeader   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 0
dl 0
loc 48
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getName() 0 4 1
A setValue() 0 5 1
A validateValue() 0 10 6
A getValue() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Explicit Architecture POC,
7
 * which is created on top of the Symfony Demo application.
8
 *
9
 * (c) Herberto Graça <[email protected]>
10
 *
11
 * For the full copyright and license information, please view the LICENSE
12
 * file that was distributed with this source code.
13
 */
14
15
namespace Acme\App\Core\Port\Notification\Client\Email;
16
17
use InvalidArgumentException;
18
19
/**
20
 * @author Herberto Graca <[email protected]>
21
 * @author Jeroen Van Den Heuvel
22
 * @author Marijn Koesen
23
 */
24
class EmailHeader
25
{
26
    /**
27
     * @var string
28
     */
29
    private $name;
30
31
    /**
32
     * @var string
33
     */
34
    private $value;
35
36
    public function __construct(string $name, string $value = '')
37
    {
38
        $this->name = $name;
39
        $this->setValue($value);
40
    }
41
42
    public function getName(): string
43
    {
44
        return $this->name;
45
    }
46
47
    protected function setValue(string $value): void
48
    {
49
        $this->validateValue($value);
50
        $this->value = $value;
51
    }
52
53
    /**
54
     * @throws InvalidArgumentException
55
     */
56
    protected function validateValue(string $value): void
57
    {
58
        if (\is_object($value) && !\method_exists($value, '__toString')) {
59
            throw new InvalidArgumentException('Object cannot be represented as a string');
60
        }
61
62
        if (!\is_object($value) && !\is_scalar($value) && !empty($value)) {
63
            throw new InvalidArgumentException('Given value is not a scalar');
64
        }
65
    }
66
67
    public function getValue(): string
68
    {
69
        return $this->value;
70
    }
71
}
72