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

CustomField::addValue()   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 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
}