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

FieldList   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 92.86%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 7
lcom 0
cbo 0
dl 0
loc 35
ccs 13
cts 14
cp 0.9286
rs 10
c 2
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getExistedValues() 0 17 4
A setFromArray() 0 6 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 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