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

FieldList   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 7
c 2
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 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