Completed
Push — master ( 65f7a2...1565b3 )
by Konstantin
07:54 queued 01:51
created

FieldList::getExistedValues()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3

Importance

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