Completed
Push — master ( 65f7a2...1565b3 )
by Konstantin
07:54 queued 01:51
created

FieldList   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 0
dl 0
loc 29
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getExistedValues() 0 11 3
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 50
    public function getExistedValues($fieldList)
16
    {
17 50
        $fields = [];
18 50
        foreach ($fieldList as $field) {
19 50
            $fields[$field] = isset($this->$field) ? $this->$field : null;
20 50
        }
21
22 50
        $fields = array_filter($fields, 'strlen');
23
24 50
        return $fields;
25
    }
26
27
    /**
28
     * @param $fieldList
29
     * @param $array
30
     */
31 18
    public function setFromArray($fieldList, $array)
32
    {
33 18
        foreach ($fieldList as $field) {
34 18
            $this->$field = isset($array[$field]) ? $array[$field] : null;
35 18
        }
36
    }
37
}