Completed
Pull Request — master (#1)
by
unknown
04:41
created

FieldList::getExistedValues()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 4.016

Importance

Changes 2
Bugs 0 Features 0
Metric Value
dl 0
loc 17
ccs 9
cts 10
cp 0.9
rs 9.2
c 2
b 0
f 0
cc 4
eloc 9
nc 3
nop 1
crap 4.016
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 77
    public function getExistedValues($fieldList)
16
    {
17 77
        $fields = [];
18 77
        foreach ($fieldList as $field) {
19 77
            $fields[$field] = isset($this->$field) ? $this->$field : null;
20
        }
21
22 77
        $fields = array_filter($fields, function ($field) {
23 77
            if (is_array($field)) {
24
                return !empty($field);
25
            }
26
27 77
            return strlen($field);
28 77
        });
29
30 77
        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
        }
42 31
    }
43
}
44