FieldList   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
c 0
b 0
f 0
lcom 0
cbo 0
dl 0
loc 35
ccs 16
cts 16
cp 1
rs 10

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 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