CustomizableEntity::get()   A
last analyzed

Complexity

Conditions 4
Paths 8

Size

Total Lines 19

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 4

Importance

Changes 0
Metric Value
dl 0
loc 19
ccs 13
cts 13
cp 1
rs 9.6333
c 0
b 0
f 0
cc 4
nc 8
nop 0
crap 4
1
<?php
2
3
namespace linkprofit\AmoCRM\entities;
4
5
/**
6
 * Class CustomizableEntity
7
 * @package linkprofit\AmoCRM\entities
8
 */
9
abstract class CustomizableEntity extends BaseEntity
10
{
11
    /**
12
     * @var CustomField[]
13
     */
14
    protected $custom_fields = [];
15
16
    /**
17
     * @param CustomField $field
18
     */
19 32
    public function addCustomField(CustomField $field)
20
    {
21 32
        $this->custom_fields[] = $field;
22 32
    }
23
24
    /**
25
     * @return array
26
     */
27 46
    public function get()
28
    {
29 46
        if ($this->id) {
30 12
            $this->setUpdatedTime();
31 12
        }
32
33 46
        $custom_fields = [];
34 46
        foreach ($this->custom_fields as $custom_field) {
35 27
            $custom_fields[] = $custom_field->get();
36 46
        }
37
38 46
        $fields = $this->getExistedValues($this->fieldList);
39
40 46
        if (count($custom_fields)) {
41 27
            $fields['custom_fields'] = $custom_fields;
42 27
        }
43
44 46
        return $fields;
45
    }
46
}