Completed
Push — master ( 012789...e65557 )
by Mark
01:48
created

Member::getCustomField()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 2
eloc 2
nc 2
nop 1
1
<?php
2
3
namespace Mrkj\Laposta\Models;
4
5
class Member
6
{
7
    public $id;
8
    public $listId;
9
    public $email;
10
    public $state;
11
    public $signupDate;
12
    public $modified;
13
    public $ip;
14
    public $sourceUrl;
15
    private $customFields = [];
16
17
    const STATE_ACTIVE = 'active';
18
    const STATE_UNSUBSCRIBED = 'unsubscribed';
19
    const STATE_CLEANED = 'cleaned';
20
21
    const STATES = [self::STATE_ACTIVE, self::STATE_UNSUBSCRIBED, self::STATE_CLEANED];
22
23
    /**
24
     * @param array $response
25
     * @return Member
26
     */
27
    public static function createFromResponse(array $response) : Member
28
    {
29
        $self = new self;
30
31
        $self->updateFromResponse($response);
32
33
        return $self;
34
    }
35
36
    /**
37
     * @param array $response
38
     */
39
    public function updateFromResponse(array $response)
40
    {
41
        $this->id = $response['member_id'];
42
        $this->listId = $response['list_id'];
43
        $this->email = $response['email'];
44
        $this->state = $response['state'];
45
        $this->signupDate = $response['signup_date'];
46
        $this->modified = $response['modified'];
47
        $this->ip = $response['ip'];
48
        $this->sourceUrl = $response['source_url'];
49
50
        $this->setCustomFields($response['custom_fields']);
51
    }
52
53
    /**
54
     * @return array
55
     */
56
    public function getCustomFields() : array
57
    {
58
        return $this->customFields;
59
    }
60
61
    /**
62
     * @param array|null $customFields
63
     */
64
    public function setCustomFields($customFields)
65
    {
66
        if (is_array($customFields)) {
67
            $this->customFields = $customFields;
68
        }
69
    }
70
71
    /**
72
     * @param $key
73
     * @param $value
74
     */
75
    public function setCustomField($key, $value)
76
    {
77
        $this->customFields[$key] = $value;
78
    }
79
80
    /**
81
     * @param $key
82
     * @return mixed
83
     */
84
    public function getCustomField($key)
85
    {
86
        return isset($this->customFields[$key]) ? $this->customFields[$key] : null;
87
    }
88
}
89