Address   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 6
c 1
b 0
f 1
lcom 1
cbo 0
dl 0
loc 72
ccs 16
cts 16
cp 1
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getAddress() 0 4 1
A getName() 0 4 1
A toString() 0 8 2
A __toString() 0 4 1
1
<?php
2
3
/**
4
 * This file is part of slick/mail package
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
namespace Slick\Mail\Header\AddressList;
11
12
/**
13
 * Address
14
 *
15
 * @package Slick\Mail\Header\AddressList
16
 * @author  Filipe Silva <[email protected]>
17
 */
18
class Address implements AddressInterface
19
{
20
21
    /**
22
     * @var string
23
     */
24
    private $address;
25
26
    /**
27
     * @var string|null
28
     */
29
    private $name;
30
31
    /**
32
     * Address
33
     *
34
     * @param $address
35
     * @param null $name
36
     *
37
     */
38 16
    public function __construct($address, $name = null)
39
    {
40 16
        $this->address = $address;
41 16
        $this->name = $name;
42 16
    }
43
44
    /**
45
     * Gets the e-mail address
46
     *
47
     * @return string
48
     */
49 16
    public function getAddress()
50
    {
51 16
        return $this->address;
52
    }
53
54
    /**
55
     * Gets the name
56
     *
57
     * @return null|string
58
     */
59 16
    public function getName()
60
    {
61 16
        return $this->name;
62
    }
63
64
    /**
65
     * Gets the string representation of this e-mail address
66
     *
67
     * @return string
68
     */
69 16
    public function toString()
70
    {
71 16
        $str = "{$this->getAddress()}";
72 16
        if ($this->name) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->name of type string|null is loosely compared to true; 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...
73 16
            $str = "{$this->getName()} <{$str}>";
74 8
        }
75 16
        return $str;
76
    }
77
78
    /**
79
     * An automated alias for toString() method
80
     *
81
     * @see Address::toString()
82
     *
83
     * @return string
84
     */
85 16
    public function __toString()
86
    {
87 16
        return $this->toString();
88
    }
89
}