1 | <?php |
||
27 | abstract class Model |
||
28 | { |
||
29 | /** |
||
30 | * The term's taxonomy |
||
31 | * @var string |
||
32 | */ |
||
33 | const TAXONOMY = ''; |
||
34 | |||
35 | /** |
||
36 | * The object type in WordPress |
||
37 | * @var string |
||
38 | */ |
||
39 | const OBJECT_TYPE = 'term'; |
||
40 | |||
41 | /** |
||
42 | * The term object |
||
43 | * @var WP_Term |
||
44 | */ |
||
45 | protected $term; |
||
46 | |||
47 | use TypeMeta; |
||
48 | use QueryBuilder; |
||
49 | |||
50 | /** |
||
51 | * Model Constructor. |
||
52 | * |
||
53 | * @param mixed $term WP_Term to fill data from |
||
54 | */ |
||
55 | public function __construct(WP_Term $term = null) |
||
66 | |||
67 | /** |
||
68 | * Create a new instance from a WP_Term object. |
||
69 | * |
||
70 | * @param WP_Term $term [description] |
||
71 | * |
||
72 | * @return static |
||
73 | */ |
||
74 | public static function fromWpTerm(WP_Term $term) |
||
78 | |||
79 | /** |
||
80 | * Create a new instance from a term ID. |
||
81 | * |
||
82 | * @param int|string $id Term ID |
||
83 | * |
||
84 | * @return static |
||
85 | */ |
||
86 | public static function fromID($id) |
||
94 | |||
95 | /** |
||
96 | * Create a new instance from a slug. |
||
97 | * |
||
98 | * @param string $slug Term slug |
||
99 | * |
||
100 | * @return static |
||
101 | */ |
||
102 | public static function fromSlug($slug) |
||
110 | |||
111 | /** |
||
112 | * Create a new instance from an array of attributes. |
||
113 | * |
||
114 | * @param array $attributes [description] |
||
115 | * |
||
116 | * @return static |
||
117 | */ |
||
118 | public static function fromArray(array $attributes) |
||
124 | |||
125 | /** |
||
126 | * Create a new term, and get the instance for it. |
||
127 | * |
||
128 | * @param array $attributes Term attributes |
||
129 | * |
||
130 | * @return static |
||
131 | */ |
||
132 | public static function create(array $attributes = []) |
||
141 | |||
142 | /** |
||
143 | * Save or update the term instance in the database. |
||
144 | * |
||
145 | * @return $this |
||
146 | */ |
||
147 | public function save() |
||
165 | |||
166 | /** |
||
167 | * Delete the term from the database. |
||
168 | * |
||
169 | * @return $this |
||
170 | */ |
||
171 | public function delete() |
||
180 | |||
181 | /** |
||
182 | * Check if this term exists in the database. |
||
183 | * |
||
184 | * @return boolean |
||
185 | */ |
||
186 | public function exists() |
||
190 | |||
191 | /** |
||
192 | * Check if this term exists in the database as the child of the given parent. |
||
193 | * |
||
194 | * @param int|string|object $parent integer Parent term ID |
||
195 | * string Parent term slug or name |
||
196 | * object The parent term object/model. |
||
197 | * |
||
198 | * @return boolean True if the this term and the parent |
||
199 | * exist in the database, and the instance |
||
200 | * is a child of the given parent; |
||
201 | * otherwise false |
||
202 | */ |
||
203 | public function isChildOf($parent) |
||
211 | |||
212 | /** |
||
213 | * Get the parent term instance. |
||
214 | * |
||
215 | * @return static |
||
216 | */ |
||
217 | public function parent() |
||
221 | |||
222 | /** |
||
223 | * Get all ancestors of this term as a collection. |
||
224 | * |
||
225 | * @return Collection |
||
226 | */ |
||
227 | public function ancestors() |
||
234 | |||
235 | /** |
||
236 | * Get the Taxonomy model. |
||
237 | * |
||
238 | * @return Taxonomy |
||
239 | */ |
||
240 | public function taxonomy() |
||
244 | |||
245 | /** |
||
246 | * Start a new query for terms of this type. |
||
247 | * |
||
248 | * @return TermQueryBuilder |
||
249 | */ |
||
250 | public function newQuery() |
||
254 | |||
255 | /** |
||
256 | * Magic Getter. |
||
257 | * |
||
258 | * @param string $property Property name accessed |
||
259 | * |
||
260 | * @return mixed |
||
261 | */ |
||
262 | public function __get($property) |
||
274 | |||
275 | /** |
||
276 | * Magic set checker. |
||
277 | * |
||
278 | * @param string $property Property name queried |
||
279 | * |
||
280 | * @return boolean |
||
281 | */ |
||
282 | public function __isset($property) |
||
286 | |||
287 | /** |
||
288 | * Magic Setter. |
||
289 | * |
||
290 | * @param string $property Property name assigned |
||
291 | * @param mixed $value Assigned property value |
||
292 | */ |
||
293 | public function __set($property, $value) |
||
297 | } |
||
298 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.