Member::setCustomFields()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 1
dl 0
loc 6
rs 10
c 0
b 0
f 0
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
    const STATE_DELETED = 'deleted';
21
22
    const STATES = [
23
        self::STATE_ACTIVE,
24
        self::STATE_UNSUBSCRIBED,
25
        self::STATE_CLEANED,
26
        self::STATE_DELETED,
27
    ];
28
29
    /**
30
     * @param array $response
31
     * @return Member
32
     */
33
    public static function createFromResponse(array $response): self
34
    {
35
        $self = new self;
36
37
        $self->updateFromResponse($response);
38
39
        return $self;
40
    }
41
42
    /**
43
     * @param array $response
44
     */
45
    public function updateFromResponse(array $response)
46
    {
47
        $this->id = $response['member_id'];
48
        $this->listId = $response['list_id'];
49
        $this->email = $response['email'];
50
        $this->state = $response['state'];
51
        $this->signupDate = $response['signup_date'];
52
        $this->modified = $response['modified'];
53
        $this->ip = $response['ip'];
54
        $this->sourceUrl = $response['source_url'];
55
56
        $this->setCustomFields($response['custom_fields']);
57
    }
58
59
    /**
60
     * @return array
61
     */
62
    public function getCustomFields(): array
63
    {
64
        return $this->customFields;
65
    }
66
67
    /**
68
     * @param array|null $customFields
69
     */
70
    public function setCustomFields($customFields)
71
    {
72
        if (is_array($customFields)) {
73
            $this->customFields = $customFields;
74
        }
75
    }
76
77
    /**
78
     * @param $key
79
     * @param $value
80
     */
81
    public function setCustomField($key, $value)
82
    {
83
        $this->customFields[$key] = $value;
84
    }
85
86
    /**
87
     * @param $key
88
     * @return mixed
89
     */
90
    public function getCustomField($key)
91
    {
92
        return isset($this->customFields[$key]) ? $this->customFields[$key] : null;
93
    }
94
}
95