EmailAddress::getHostname()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Ddeboer\Imap\Message;
4
5
/**
6
 * An e-mail address
7
 */
8
class EmailAddress
9
{
10
    private $mailbox;
11
    private $hostname;
12
    private $name;
13
    private $address;
14
15
    public function __construct($mailbox, $hostname = null, $name = null)
16
    {
17
        $this->mailbox = $mailbox;
18
        $this->hostname = $hostname;
19
        $this->name = $name;
20
        
21
        if ($hostname) {
22
            $this->address = $mailbox . '@' . $hostname;
23
        }
24
    }
25
26
    public function getAddress()
27
    {
28
        return $this->address;
29
    }
30
31
    /**
32
     * Returns address with person name
33
     *
34
     * @return string
35
     */
36
    public function getFullAddress()
37
    {
38
        if ($this->name) {
39
            $address = sprintf("%s <%s@%s>", $this->name, $this->mailbox, $this->hostname);
40
        } else {
41
            $address = sprintf("%s@%s", $this->mailbox, $this->hostname);
42
        }
43
44
        return $address;
45
    }
46
47
    public function getMailbox()
48
    {
49
        return $this->mailbox;
50
    }
51
52
    public function getHostname()
53
    {
54
        return $this->hostname;
55
    }
56
57
    public function getName()
58
    {
59
        return $this->name;
60
    }
61
62
    public function __toString()
63
    {
64
        return $this->getAddress();
65
    }
66
}
67