Completed
Push — master ( 096858...7ec34d )
by Gabriel
03:50
created

MappingData::fromArray()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 3
c 1
b 0
f 0
nc 3
nop 1
dl 0
loc 5
ccs 4
cts 4
cp 1
crap 3
rs 10
1
<?php
2
3
namespace Nip\Records\Mapping;
4
5
/**
6
 * Class MappingData
7
 * @package Nip\Records\Mapping
8
 */
9
class MappingData implements \Serializable
10
{
11
    protected $table;
12
    protected $controller;
13
    protected $model;
14
    protected $tableStructure;
15
    protected $fields;
16
    protected $bootTraits;
17
18
    /**
19
     * @return mixed
20
     */
21 1
    public function getTable()
22
    {
23 1
        return $this->table;
24
    }
25
26
    /**
27
     * @return bool
28
     */
29 1
    public function hasTable(): bool
30
    {
31 1
        return is_string($this->table);
32
    }
33
34
    /**
35
     * @param mixed $table
36
     */
37 4
    public function setTable($table): void
38
    {
39 4
        $this->table = $table;
40 4
    }
41
42
    /**
43
     * @return mixed
44
     */
45 1
    public function getController()
46
    {
47 1
        return $this->controller;
48
    }
49
50
    /**
51
     * @param mixed $controller
52
     */
53 3
    public function setController($controller): void
54
    {
55 3
        $this->controller = $controller;
56 3
    }
57
58 1
    public function hasController(): bool
59
    {
60 1
        return !empty($this->controller);
61
    }
62
63
    /**
64
     * @return mixed
65
     */
66 1
    public function getModel()
67
    {
68 1
        return $this->model;
69
    }
70
71
    /**
72
     * @param mixed $model
73
     */
74 3
    public function setModel($model): void
75
    {
76 3
        $this->model = $model;
77 3
    }
78
79 1
    public function hasModel(): bool
80
    {
81 1
        return !empty($this->model);
82
    }
83
84
85
    /**
86
     * @return mixed
87
     */
88 1
    public function getTableStructure()
89
    {
90 1
        return $this->tableStructure;
91
    }
92
93
    /**
94
     * @return bool
95
     */
96 1
    public function hasTableStructure(): bool
97
    {
98 1
        return is_array($this->tableStructure);
99
    }
100
101
    /**
102
     * @param mixed $tableStructure
103
     */
104 3
    public function setTableStructure($tableStructure): void
105
    {
106 3
        $this->tableStructure = $tableStructure;
107 3
    }
108
109
    /**
110
     * @return mixed
111
     */
112 1
    public function getFields()
113
    {
114 1
        return $this->fields;
115
    }
116
117
    /**
118
     * @return bool
119
     */
120 1
    public function hasFields(): bool
121
    {
122 1
        return is_array($this->fields);
123
    }
124
125
    /**
126
     * @param mixed $fields
127
     */
128 3
    public function setFields($fields): void
129
    {
130 3
        $this->fields = $fields;
131 3
    }
132
133
    /**
134
     * @return mixed
135
     */
136 1
    public function getBootTraits()
137
    {
138 1
        return $this->bootTraits;
139
    }
140
141
    /**
142
     * @param mixed $bootTraits
143
     */
144 3
    public function setBootTraits($bootTraits): void
145
    {
146 3
        $this->bootTraits = $bootTraits;
147 3
    }
148
149 1
    public function hasBootTraits(): bool
150
    {
151 1
        return is_array($this->bootTraits);
152
    }
153
154
155
    /**
156
     * @inheritDoc
157
     */
158 2
    public function serialize()
159
    {
160 2
        $data = [];
161 2
        $properties = ['table', 'model', 'controller', 'tableStructure', 'fields', 'bootTraits'];
162 2
        foreach ($properties as $property) {
163 2
            $data[$property] = $this->{$property};
164
        }
165 2
        return serialize($data);
166
    }
167
168
    /**
169
     * Constructs the object
170
     * @link https://php.net/manual/en/serializable.unserialize.php
171
     * @param string $serialized <p>
172
     * The string representation of the object.
173
     * </p>
174
     * @return void
175
     */
176 1
    public function unserialize($serialized)
177
    {
178 1
        $data = unserialize($serialized);
179 1
        $this->fromArray($data);
180 1
    }
181
182
    /**
183
     * @param $data
184
     */
185 1
    public function fromArray($data)
186
    {
187 1
        foreach ($data as $key=>$value) {
188 1
            if (property_exists($this, $key)) {
189 1
                $this->{$key} = $value;
190
            }
191
        }
192 1
    }
193
194
}