Entity   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 0
dl 0
loc 58
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getId() 0 4 1
A extract() 0 12 2
A populate() 0 12 2
1
<?php
2
3
namespace T4webDomain;
4
5
use T4webDomainInterface\EntityInterface;
6
7
class Entity implements EntityInterface
8
{
9
10
    /**
11
     * @var mixed
12
     */
13
    protected $id;
14
15
    /**
16
     * @param array $data
17
     */
18
    public function __construct(array $data = [])
19
    {
20
        $this->populate($data);
21
    }
22
23
    /**
24
     * @return mixed
25
     */
26
    public function getId()
27
    {
28
        return $this->id;
29
    }
30
31
    /**
32
     * @param array $properties
33
     * @return array
34
     */
35
    public function extract(array $properties = [])
36
    {
37
        $state = get_object_vars($this);
38
39
        if (empty($properties)) {
40
            return $state;
41
        }
42
43
        $rawArray = array_fill_keys($properties, null);
44
45
        return array_intersect_key($state, $rawArray);
46
    }
47
48
    /**
49
     * @param array $array
50
     * @return $this
51
     */
52
    public function populate(array $array = [])
53
    {
54
        $state = get_object_vars($this);
55
56
        $stateIntersect = array_intersect_key($array, $state);
57
58
        foreach ($stateIntersect as $key => $value) {
59
            $this->$key = $value;
60
        }
61
62
        return $this;
63
    }
64
}
65