FieldList::getExistedValues()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 4

Importance

Changes 0
Metric Value
dl 0
loc 17
ccs 11
cts 11
cp 1
rs 9.7
c 0
b 0
f 0
cc 4
nc 3
nop 1
crap 4
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 103
    public function getExistedValues($fieldList)
16
    {
17 103
        $fields = [];
18 103
        foreach ($fieldList as $field) {
19 103
            $fields[$field] = isset($this->$field) ? $this->$field : null;
20 103
        }
21
22 103
        $fields = array_filter($fields, function($field) {
23 103
            if (is_array($field)) {
24 7
                return !empty($field);
25
            }
26
27 103
            return strlen($field);
28 103
        });
29
30 103
        return $fields;
31
    }
32
33
    /**
34
     * @param $fieldList
35
     * @param $array
36
     */
37 54
    public function setFromArray($fieldList, $array)
38
    {
39 54
        foreach ($fieldList as $field) {
40 54
            $this->$field = isset($array[$field]) ? $array[$field] : null;
41 54
        }
42 54
    }
43
}
44