GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

Address::__construct()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 4
nc 4
nop 2
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * This file is part of the O2System Framework package.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 *
8
 * @author         Steeve Andrian Salim
9
 * @copyright      Copyright (c) Steeve Andrian Salim
10
 */
11
12
// ------------------------------------------------------------------------
13
14
namespace O2System\Email;
15
16
// ------------------------------------------------------------------------
17
18
/**
19
 * Class Address
20
 *
21
 * @package O2System\Email
22
 */
23
class Address
24
{
25
    /**
26
     * Address::$email
27
     *
28
     * Email address.
29
     *
30
     * @var string
31
     */
32
    protected $email;
33
34
    /**
35
     * Address::$name
36
     *
37
     * Email owner name.
38
     *
39
     * @var string
40
     */
41
    protected $name;
42
43
    // ------------------------------------------------------------------------
44
45
    /**
46
     * Address::__construct
47
     *
48
     * @param string      $email
49
     * @param string|null $name
50
     */
51
    public function __construct($email = null, $name = null)
52
    {
53
        if (isset($email)) {
54
            $this->setEmail($email);
55
        }
56
57
        if (isset($name)) {
58
            $this->setName($name);
59
        }
60
    }
61
62
    // ------------------------------------------------------------------------
63
64
    /**
65
     * Address::__toString
66
     */
67
    public function __toString()
68
    {
69
        $string = '';
70
71
        if (false !== ($email = $this->getEmail())) {
72
            $string = $email;
73
        }
74
75
        if (false !== ($name = $this->getName())) {
76
            $string .= ' <' . $name . '>';
77
        }
78
79
        return $string;
80
    }
81
82
    // ------------------------------------------------------------------------
83
84
    /**
85
     * Address::getEmail
86
     *
87
     * Gets email address.
88
     *
89
     * @return bool|string
90
     */
91
    public function getEmail()
92
    {
93
        if (empty($this->email)) {
94
            return false;
95
        }
96
97
        return $this->email;
98
    }
99
100
    // ------------------------------------------------------------------------
101
102
    /**
103
     * Address::setEmail
104
     *
105
     * @param string $email
106
     *
107
     * @return static
108
     */
109
    public function setEmail($email)
110
    {
111
        $email = trim($email);
112
113
        if (preg_match('/\<(.*)\>/', $email, $matches)) {
114
            $email = trim(str_replace($matches[ 0 ], '', $email));
115
            $name = $matches[ 1 ];
116
        }
117
118
        if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
119
            $this->email = $email;
120
121
            if (isset($name)) {
122
                $this->setName($name);
123
            }
124
        }
125
126
        return $this;
127
    }
128
129
    // ------------------------------------------------------------------------
130
131
    /**
132
     * Address::getName
133
     *
134
     * Gets email owner name.
135
     *
136
     * @return bool|string
137
     */
138
    public function getName()
139
    {
140
        if (empty($this->name)) {
141
            return false;
142
        }
143
144
        return $this->name;
145
    }
146
147
    // ------------------------------------------------------------------------
148
149
    /**
150
     * Address::setName
151
     *
152
     * @param string $name
153
     *
154
     * @return static
155
     */
156
    public function setName($name)
157
    {
158
        $name = trim($name);
159
160
        if ($name !== '') {
161
            $this->name = $name;
162
        }
163
164
        return $this;
165
    }
166
}