EmailAddress   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 0
dl 0
loc 37
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getEmail() 0 4 1
A getName() 0 4 1
A __toString() 0 8 2
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
/**
18
 * @author Marijn Koesen
19
 * @author Herberto Graca <[email protected]>
20
 */
21
class EmailAddress
22
{
23
    /**
24
     * @var string
25
     */
26
    private $email;
27
28
    /**
29
     * @var string|null
30
     */
31
    private $name;
32
33
    public function __construct(string $email, string $name = null)
34
    {
35
        $this->email = $email;
36
        $this->name = $name;
37
    }
38
39
    public function getEmail(): string
40
    {
41
        return $this->email;
42
    }
43
44
    public function getName(): ?string
45
    {
46
        return $this->name;
47
    }
48
49
    public function __toString(): string
50
    {
51
        if (!$this->name) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->name of type string|null is loosely compared to false; this is ambiguous if the string can be empty. You might want to explicitly use === null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
52
            return $this->email;
53
        }
54
55
        return sprintf('%s <%s>', $this->name, $this->email);
56
    }
57
}
58