Completed
Push — master ( 2994aa...19d116 )
by Patrick
08:28
created

BaseModel   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 76
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 50%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 0
dl 0
loc 76
ccs 7
cts 14
cp 0.5
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getData() 0 4 1
A getDataProperty() 0 4 2
A __get() 0 8 2
A __set() 0 4 1
1
<?php
2
namespace Dropbox\Models;
3
4
class BaseModel implements ModelInterface
5
{
6
7
    /**
8
     * Model Data
9
     *
10
     * @var array
11
     */
12
    protected $data;
13
14
    /**
15
     * Create a new Model instance
16
     *
17
     * @param array $data
18
     */
19 36
    public function __construct(array $data)
20
    {
21 36
        $this->data = $data;
22 36
    }
23
24
    /**
25
     * Get the Model data
26
     *
27
     * @return array
28
     */
29 1
    public function getData()
30
    {
31 1
        return $this->data;
32
    }
33
34
    /**
35
     * Get Data Property
36
     *
37
     * @param  string $property
38
     *
39
     * @return mixed
40
     */
41 35
    public function getDataProperty($property)
42
    {
43 35
        return isset($this->data[$property]) ? $this->data[$property] : null;
44
    }
45
46
    /**
47
     * Handle calls to undefined properties.
48
     * Check whether an item with the key,
49
     * same as the property, is available
50
     * on the data property.
51
     *
52
     * @param  string $property
53
     *
54
     * @return mixed|null
55
     */
56
    public function __get($property)
57
    {
58
        if (array_key_exists($property, $this->getData())) {
59
            return $this->getData()[$property];
60
        }
61
62
        return null;
63
    }
64
65
    /**
66
     * Handle calls to undefined properties.
67
     * Sets an item with the defined value
68
     * on the data property.
69
     *
70
     * @param  string $property
71
     * @param  string $value
72
     *
73
     * @return mixed|null
74
     */
75
    public function __set($property, $value)
76
    {
77
        $this->data[$property] = $value;
78
    }
79
}
80