Completed
Push — master ( ff21ca...f317b4 )
by Konstantin
02:12
created

CustomField::get()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 15
Code Lines 8

Duplication

Lines 15
Ratio 100 %

Code Coverage

Tests 8
CRAP Score 3

Importance

Changes 0
Metric Value
dl 15
loc 15
ccs 8
cts 8
cp 1
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 8
nc 4
nop 0
crap 3
1
<?php
2
3
namespace linkprofit\AmoCRM\entities;
4
5
use linkprofit\AmoCRM\traits\FieldsTrait;
6
7
/**
8
 * Class CustomField
9
 * @package linkprofit\AmoCRM
10
 */
11
class CustomField implements EntityInterface
12
{
13
    public $id;
14
    public $name;
15
    public $code;
16
17
    use FieldsTrait;
18
19
    /**
20
     * @var array Value
21
     */
22
    protected $values = [];
23
24
    protected $fieldList = [
25
        'id', 'name', 'code'
26
    ];
27
28 4
    public function __construct($id, $name, $code)
29
    {
30 4
        $this->id = $id;
31 4
        $this->name = $name;
32 4
        $this->code = $code;
33 4
    }
34
35
    /**
36
     * @param Value $value
37
     */
38 3
    public function addValue(Value $value)
39
    {
40 3
        $this->values[] = $value;
41 3
    }
42
43
    /**
44
     * @return array
45
     */
46 4 View Code Duplication
    public function get()
1 ignored issue
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
47
    {
48 4
        $fields = $this->getExistedValues($this->fieldList);
49
50 4
        $values = [];
51 4
        foreach ($this->values as $value) {
52 3
            $values[] = $value->get();
53
        }
54
55 4
        if (count($values)) {
56 3
            $fields['values'] = $values;
57
        }
58
59 4
        return $fields;
60
    }
61
}