Completed
Push — master ( 9ec94a...174e63 )
by Mark
01:43
created

Member::setState()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
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