Segment   A
last analyzed

Complexity

Total Complexity 20

Size/Duplication

Total Lines 156
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 156
rs 10
c 0
b 0
f 0
wmc 20
lcom 1
cbo 0

12 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A __toString() 0 4 1
A getId() 0 4 1
A setId() 0 4 1
A getContactListId() 0 4 1
A setContactListId() 0 4 1
A getName() 0 4 1
A setName() 0 4 1
A getCql() 0 4 1
A setCql() 0 4 1
A toAPI() 0 22 5
A fromAPI() 0 18 5
1
<?php
2
3
namespace Mailxpert\Model;
4
5
/**
6
 * Class Segment
7
 * @package Mailxpert\Model
8
 */
9
class Segment
10
{
11
    /**
12
     * @var string
13
     */
14
    private $id;
15
16
    /**
17
     * @var string
18
     */
19
    private $contactListId;
20
21
    /**
22
     * @var string
23
     */
24
    private $name;
25
26
    /**
27
     * @var string
28
     */
29
    private $cql;
30
31
    /**
32
     * Segment constructor.
33
     *
34
     * @param string $id
35
     */
36
    public function __construct($id = null)
37
    {
38
        $this->id = $id;
39
    }
40
41
    /**
42
     * @return string
43
     */
44
    public function __toString()
45
    {
46
        return (string) $this->getId();
47
    }
48
49
50
    /**
51
     * @return string
52
     */
53
    public function getId()
54
    {
55
        return $this->id;
56
    }
57
58
    /**
59
     * @param string $id
60
     */
61
    public function setId($id)
62
    {
63
        $this->id = $id;
64
    }
65
66
    /**
67
     * @return string
68
     */
69
    public function getContactListId()
70
    {
71
        return $this->contactListId;
72
    }
73
74
    /**
75
     * @param string $contactListId
76
     */
77
    public function setContactListId($contactListId)
78
    {
79
        $this->contactListId = $contactListId;
80
    }
81
82
    /**
83
     * @return string
84
     */
85
    public function getName()
86
    {
87
        return $this->name;
88
    }
89
90
    /**
91
     * @param string $name
92
     */
93
    public function setName($name)
94
    {
95
        $this->name = $name;
96
    }
97
98
    /**
99
     * @return string
100
     */
101
    public function getCql()
102
    {
103
        return $this->cql;
104
    }
105
106
    /**
107
     * @param string $cql
108
     */
109
    public function setCql($cql)
110
    {
111
        $this->cql = $cql;
112
    }
113
114
    /**
115
     * @param array $exclude
116
     * @param bool  $clean
117
     *
118
     * @return array
119
     */
120
    public function toAPI(array $exclude = [], $clean = true)
121
    {
122
        $data = [
123
            "contact_list_id" => $this->getContactListId(),
124
            "name" => $this->getName(),
125
            "cql" => $this->getCql(),
126
        ];
127
128
        if ($clean) {
129
            foreach ($data as $key => $value) {
130
                if (empty($value)) {
131
                    unset($data[$key]);
132
                }
133
            }
134
        }
135
136
        foreach ($exclude as $field) {
137
            unset($data[$field]);
138
        }
139
140
        return $data;
141
    }
142
143
    /**
144
     * @param array $data
145
     */
146
    public function fromAPI(array $data)
147
    {
148
        foreach ($data as $key => $value) {
149
            switch ($key) {
150
                case "contact_list_id":
151
                    $this->setContactListId($value);
152
                    break;
153
                case "name":
154
                    $this->setName($value);
155
                    break;
156
                case "cql":
157
                    $this->setCql($value);
158
                    break;
159
                default:
160
                    break;
161
            }
162
        }
163
    }
164
}
165