1 | <?php |
||
12 | abstract class Model |
||
13 | { |
||
14 | /** |
||
15 | * The core model object |
||
16 | * @var object |
||
17 | */ |
||
18 | protected $object; |
||
19 | |||
20 | /** |
||
21 | * Type object property aliases |
||
22 | * @var array |
||
23 | */ |
||
24 | protected $objectAliases = [ |
||
25 | // 'aliasName' => 'propertyNameOnObject' |
||
|
|||
26 | ]; |
||
27 | |||
28 | /** |
||
29 | * The object type in WordPress |
||
30 | */ |
||
31 | const OBJECT_TYPE = ''; |
||
32 | |||
33 | /** |
||
34 | * The name of the primary ID property on the object |
||
35 | */ |
||
36 | const ID_PROPERTY = ''; |
||
37 | |||
38 | /** |
||
39 | * Get a new query builder for the model. |
||
40 | * |
||
41 | * @return \Silk\Contracts\BuildsQueries |
||
42 | */ |
||
43 | abstract public function newQuery(); |
||
44 | |||
45 | /** |
||
46 | * Save the changes to the database. |
||
47 | * |
||
48 | * @return $this |
||
49 | */ |
||
50 | abstract public function save(); |
||
51 | |||
52 | /** |
||
53 | * Delete the modeled record from the database. |
||
54 | * |
||
55 | * @return $this |
||
56 | */ |
||
57 | abstract public function delete(); |
||
58 | |||
59 | /** |
||
60 | * Reload the object from the database. |
||
61 | * |
||
62 | * @return $this |
||
63 | */ |
||
64 | abstract public function refresh(); |
||
65 | |||
66 | /** |
||
67 | * Make new instance. |
||
68 | * |
||
69 | * All provided arguments are forwarded to the constructor of the called class. |
||
70 | * |
||
71 | * @return static |
||
72 | */ |
||
73 | public static function make() |
||
81 | |||
82 | /** |
||
83 | * Fill the model with an array of attributes. |
||
84 | * |
||
85 | * @param array $attributes |
||
86 | * |
||
87 | * @return $this |
||
88 | */ |
||
89 | public function fill(array $attributes) |
||
102 | |||
103 | /** |
||
104 | * Create a new model of the model's type, and save it to the database. |
||
105 | * |
||
106 | * @param array $attributes |
||
107 | * |
||
108 | * @return static |
||
109 | */ |
||
110 | public static function create($attributes = []) |
||
116 | |||
117 | /** |
||
118 | * Create a new query builder instance for this model type. |
||
119 | * |
||
120 | * @return \Silk\Contracts\BuildsQueries |
||
121 | */ |
||
122 | public static function query() |
||
126 | |||
127 | /** |
||
128 | * Meta API for this type |
||
129 | * |
||
130 | * @param string $key Meta key to retrieve or empty to retrieve all. |
||
131 | * |
||
132 | * @return ObjectMeta|\Silk\Meta\Meta |
||
133 | */ |
||
134 | public function meta($key = '') |
||
144 | |||
145 | /** |
||
146 | * Set the primary ID on the model. |
||
147 | * |
||
148 | * @param string|int $id The model's ID |
||
149 | * |
||
150 | * @return $this |
||
151 | */ |
||
152 | protected function setId($id) |
||
158 | |||
159 | /** |
||
160 | * Set the object for the model. |
||
161 | * |
||
162 | * @param $object |
||
163 | * |
||
164 | * @return $this |
||
165 | */ |
||
166 | protected function setObject($object) |
||
172 | |||
173 | /** |
||
174 | * Set a property on the aliased object. |
||
175 | * |
||
176 | * @param string $key The alias name on the model |
||
177 | * @param mixed $value The value to set on the aliased object |
||
178 | * |
||
179 | * @return bool True if the alias was resolved and set; otherwise false |
||
180 | */ |
||
181 | protected function aliasSet($key, $value) |
||
194 | |||
195 | /** |
||
196 | * Get a property from the aliased object by the model's key. |
||
197 | * |
||
198 | * @param $key |
||
199 | * |
||
200 | * @return mixed|null |
||
201 | */ |
||
202 | protected function aliasGet($key) |
||
210 | |||
211 | /** |
||
212 | * Get the aliased object instance. |
||
213 | * |
||
214 | * @return object |
||
215 | */ |
||
216 | protected function getAliasedObject() |
||
220 | |||
221 | /** |
||
222 | * Expands an alias into its respective object property name. |
||
223 | * |
||
224 | * @param string $key Alias key |
||
225 | * |
||
226 | * @return string|false The expanded alias, or false no alias exists for the key. |
||
227 | */ |
||
228 | protected function expandAlias($key) |
||
232 | |||
233 | /** |
||
234 | * Magic getter. |
||
235 | * |
||
236 | * @param string $property |
||
237 | * |
||
238 | * @return mixed |
||
239 | */ |
||
240 | public function __get($property) |
||
261 | |||
262 | /** |
||
263 | * Magic Isset Checker. |
||
264 | * |
||
265 | * @return bool |
||
266 | */ |
||
267 | public function __isset($property) |
||
271 | |||
272 | /** |
||
273 | * Magic setter. |
||
274 | * |
||
275 | * @param string $property The property name |
||
276 | * @param mixed $value The new property value |
||
277 | */ |
||
278 | public function __set($property, $value) |
||
286 | |||
287 | /** |
||
288 | * Handle dynamic method calls into the model. |
||
289 | * |
||
290 | * @param string $method |
||
291 | * @param array $arguments |
||
292 | * |
||
293 | * @return mixed |
||
294 | */ |
||
295 | public function __call($method, $arguments) |
||
301 | |||
302 | /** |
||
303 | * Handle dynamic static method calls on the model class. |
||
304 | * |
||
305 | * Proxies calls to direct method calls on a new instance |
||
306 | * |
||
307 | * @param string $method |
||
308 | * @param array $arguments |
||
309 | * |
||
310 | * @return mixed |
||
311 | */ |
||
312 | public static function __callStatic($method, array $arguments) |
||
316 | } |
||
317 |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.