EmailAddress   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 6
Bugs 1 Features 2
Metric Value
wmc 9
c 6
b 1
f 2
lcom 1
cbo 0
dl 0
loc 59
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 2
A getAddress() 0 4 1
A getFullAddress() 0 10 2
A getMailbox() 0 4 1
A getHostname() 0 4 1
A getName() 0 4 1
A __toString() 0 4 1
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