Completed
Push — master ( 689800...fe66cd )
by Konstantin
01:50
created

FieldsTrait   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 FieldsTrait
7
 * @package linkprofit\AmoCRM\traits
8
 */
9
trait FieldsTrait
10
{
11
    /**
12
     * @param $fieldList
13
     * @return array
14
     */
15 13
    public function getExistedValues($fieldList)
16
    {
17 13
        $fields = [];
18 13
        foreach ($fieldList as $field) {
19 13
            $fields[$field] = isset($this->$field) ? $this->$field : null;
20 13
        }
21
22 13
        $fields = array_filter($fields, 'strlen');
23
24 13
        return $fields;
25
    }
26
27
    /**
28
     * @param $fieldList
29
     * @param $array
30
     */
31 3
    public function setFromArray($fieldList, $array)
32
    {
33 3
        foreach ($fieldList as $field) {
34 3
            $this->$field = isset($array[$field]) ? $array[$field] : null;
35 3
        }
36
    }
37
}