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

CustomizableEntity   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 0
loc 34
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A addCustomField() 0 4 1
A get() 0 15 3
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
}