Completed
Push — master ( 689800...fe66cd )
by Konstantin
01:50
created

FieldsTrait::setFromArray()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 5
cts 5
cp 1
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 3
nc 3
nop 2
crap 3
1
<?php
2
3
namespace linkprofit\AmoCRM\traits;
4
5
/**
6
 * Class FieldsTrait
7
 * @package linkprofit\AmoCRM\traits
8
 */
9
trait FieldsTrait
10
{
11
    /**
12
     * @param $fieldList
13
     * @return array
14
     */
15 13
    public function getExistedValues($fieldList)
16
    {
17 13
        $fields = [];
18 13
        foreach ($fieldList as $field) {
19 13
            $fields[$field] = isset($this->$field) ? $this->$field : null;
20 13
        }
21
22 13
        $fields = array_filter($fields, 'strlen');
23
24 13
        return $fields;
25
    }
26
27
    /**
28
     * @param $fieldList
29
     * @param $array
30
     */
31 3
    public function setFromArray($fieldList, $array)
32
    {
33 3
        foreach ($fieldList as $field) {
34 3
            $this->$field = isset($array[$field]) ? $array[$field] : null;
35 3
        }
36
    }
37
}