Contact::setAmoLinkedLeadsID()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 0
cts 3
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 2
1
<?php
2
3
namespace mb24dev\AmoCRM\Entity;
4
5
/**
6
 * Class Contact
7
 *
8
 * @package mb24dev\AmoCRM\Entity
9
 */
10
class Contact implements AmoEntityInterface, AmoIdentityInterface
11
{
12
    private $id;
13
    private $name;
14
    private $requestID;
15
    private $responsibleUserID;
16
    private $linkedLeadsID;
17
    private $companyName;
18
    private $tags;
19
20
    /**
21
     * @var \DateTime
22
     */
23
    private $dateCreate;
24
25
    /**
26
     * @var \DateTime
27
     */
28
    private $lastModified;
29
30
    /**
31
     * @var AmoEntityInterface[]
32
     */
33
    private $customFields = [];
34
35
    /**
36
     * Contact constructor.
37
     *
38
     * @param $name
39
     */
40
    public function __construct($name)
41
    {
42
        $this->name = $name;
43
    }
44
45
    /**
46
     * @param mixed $id
47
     * @return $this
48
     */
49
    public function setAmoID($id)
50
    {
51
        $this->id = $id;
52
53
        return $this;
54
    }
55
56
    /**
57
     * @return mixed
58
     */
59
    public function getAmoID()
60
    {
61
        return $this->id;
62
    }
63
64
    /**
65
     * @param mixed $requestID
66
     * @return $this
67
     */
68
    public function setAmoRequestID($requestID)
69
    {
70
        $this->requestID = $requestID;
71
72
        return $this;
73
    }
74
75
    /**
76
     * @param \DateTime $dateCreate
77
     * @return $this
78
     */
79
    public function setAmoDateCreate(\DateTime $dateCreate)
80
    {
81
        $this->dateCreate = $dateCreate;
82
83
        return $this;
84
    }
85
86
    /**
87
     * @param \DateTime $lastModified
88
     * @return $this
89
     */
90
    public function setAmoLastModified(\DateTime $lastModified)
91
    {
92
        $this->lastModified = $lastModified;
93
94
        return $this;
95
    }
96
97
    /**
98
     * @param mixed $responsibleUserID
99
     * @return $this
100
     */
101
    public function setAmoResponsibleUserID($responsibleUserID)
102
    {
103
        $this->responsibleUserID = $responsibleUserID;
104
105
        return $this;
106
    }
107
108
    /**
109
     * @param array $linkedLeadsID
110
     * @return $this
111
     */
112
    public function setAmoLinkedLeadsID(array $linkedLeadsID)
113
    {
114
        $this->linkedLeadsID = $linkedLeadsID;
115
116
        return $this;
117
    }
118
119
    /**
120
     * @param mixed $companyName
121
     * @return $this
122
     */
123
    public function setAmoCompanyName($companyName)
124
    {
125
        $this->companyName = $companyName;
126
127
        return $this;
128
    }
129
130
    /**
131
     * @param CustomField[] $customFields
132
     * @return $this
133
     */
134
    public function setAmoCustomFields($customFields)
135
    {
136
        if (!is_array($customFields)) {
137
            $customFields = [$customFields];
138
        }
139
140
        $this->customFields = $customFields;
141
142
        return $this;
143
    }
144
145
    /**
146
     * @param string $tags
147
     * @return $this
148
     */
149
    public function setAmoTags($tags)
150
    {
151
        $this->tags = $tags;
152
153
        return $this;
154
    }
155
156
    /**
157
     * @return array
158
     */
159
    public function toAmoArray()
160
    {
161
        return [
162
            'id' => $this->id,
163
            'name' => $this->name,
164
            'date_create' => $this->dateCreate ? $this->dateCreate->getTimestamp() : null,
165
            'last_modified' => $this->lastModified ? $this->lastModified->getTimestamp() : null,
166
            'request_id' => $this->requestID,
167
            'responsible_user_id' => $this->responsibleUserID,
168
            'linked_leads_id' => $this->linkedLeadsID,
169
            'company_name' => $this->companyName,
170
            'custom_fields' => array_map(
171
                function (AmoEntityInterface $customField) {
172
                    return $customField->toAmoArray();
173
                },
174
                $this->customFields
175
            ),
176
            'tags' => $this->tags,
177
        ];
178
    }
179
180
}
181