Completed
Push — master ( a9caea...8d34b7 )
by Konstantin
04:56 queued 02:10
created

FieldList::getExistedValues()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 4

Importance

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