Completed
Push — master ( 689800...fe66cd )
by Konstantin
01:50
created

Lead::set()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
namespace linkprofit\AmoCRM\entities;
4
5
use linkprofit\AmoCRM\traits\FieldsTrait;
6
7
/**
8
 * Class Lead
9
 * @package linkprofit\AmoCRM\entities
10
 */
11
class Lead implements EntityInterface
12
{
13
    public $id;
14
    public $name;
15
    public $created_at;
16
    public $updated_at;
17
    public $status_id;
18
    public $pipeline_id;
19
    public $responsible_user_id;
20
    public $sale;
21
    public $tags;
22
    public $contacts_id;
23
    public $company_id;
24
    public $custom_fields = [];
25
    public $price;
26
27
    protected $fieldList = [
28
        'id', 'name', 'created_at', 'updated_at',
29
        'status_id', 'pipeline_id', 'responsible_user_id',
30
        'sale', 'tags', 'contacts_id', 'company_id', 'price'
31
    ];
32
33
    use FieldsTrait;
34
35
    /**
36
     * @param CustomField $field
37
     */
38 4
    public function addCustomField(CustomField $field)
39
    {
40 4
        $this->custom_fields[] = $field;
41 4
    }
42
43
    /**
44
     * @return array
45
     */
46 5
    public function get()
47
    {
48 5
        $custom_fields = [];
49 5
        foreach ($this->custom_fields as $custom_field) {
50 4
            $custom_fields[] = $custom_field->get();
51 5
        }
52
53 5
        $fields = $this->getExistedValues($this->fieldList);
54
55 5
        if (count($custom_fields)) {
56 4
            $fields['custom_fields'] = $custom_fields;
57 4
        }
58
59 5
        return $fields;
60
    }
61
62
    /**
63
     * @param $array
64
     */
65 2
    public function set($array)
66
    {
67 2
        $this->setFromArray($this->fieldList, $array);
68
    }
69
}