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

BaseModel::__set()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 3
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 2
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