Completed
Push — master ( fe66cd...3af1a2 )
by Konstantin
02:26
created

CustomizableEntity::addCustomField()   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 CustomizableEntity
9
 * @package linkprofit\AmoCRM\entities
10
 */
11
abstract class CustomizableEntity implements EntityInterface
12
{
13
    protected $fieldList;
14
    protected $custom_fields = [];
15
16
    use FieldsTrait;
17
18
    /**
19
     * @param CustomField $field
20
     */
21 8
    public function addCustomField(CustomField $field)
22
    {
23 8
        $this->custom_fields[] = $field;
24 8
    }
25
26
    /**
27
     * @return array
28
     */
29 11
    public function get()
30
    {
31 11
        $custom_fields = [];
32 11
        foreach ($this->custom_fields as $custom_field) {
33 8
            $custom_fields[] = $custom_field->get();
34
        }
35
36 11
        $fields = $this->getExistedValues($this->fieldList);
37
38 11
        if (count($custom_fields)) {
39 8
            $fields['custom_fields'] = $custom_fields;
40
        }
41
42 11
        return $fields;
43
    }
44
}