Object::__get()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 1
1
<?php
2
3
namespace Inbounder\Parsers\Objects;
4
5
use Exception as MissingAttributeException;
6
use Illuminate\Contracts\Support\Arrayable;
7
8
class Object implements Arrayable
9
{
10
    /**
11
     * Attributes.
12
     */
13
    protected $attributes = [];
14
15
    /**
16
     * Constructor.
17
     */
18
    public function __construct($email, $name = null, $mailboxHash = null)
19
    {
20
        $this->attributes['email'] = $email;
21
        $this->attributes['name'] = $name;
22
        $this->attributes['mailboxHash'] = $mailboxHash;
23
    }
24
25
    /**
26
     * Setter.
27
     */
28
    public function __set($name, $value)
29
    {
30
        $this->attributes[$name] = $value;
31
    }
32
33
    /**
34
     * Getter.
35
     */
36
    public function __get($name)
37
    {
38
        if (!array_key_exists($name, $this->attributes)) {
39
            throw new MissingAttributeException("The attribute $name does not exists.", 1);
40
        }
41
42
        return $this->attributes[$name];
43
    }
44
45
    /**
46
     * Get the instance as an array.
47
     *
48
     * @return array
49
     */
50
    public function toArray()
51
    {
52
        return $this->attributes;
53
    }
54
}
55