@@ -14,7 +14,7 @@ discard block |
||
| 14 | 14 | * |
| 15 | 15 | * @return Model|WP_Error |
| 16 | 16 | */ |
| 17 | - public function find( $class, $id ); |
|
| 17 | + public function find($class, $id); |
|
| 18 | 18 | |
| 19 | 19 | /** |
| 20 | 20 | * Finds all the models of the provided class for the given params. |
@@ -26,7 +26,7 @@ discard block |
||
| 26 | 26 | * |
| 27 | 27 | * @return Collection|WP_Error |
| 28 | 28 | */ |
| 29 | - public function find_by( $class, $params = array() ); |
|
| 29 | + public function find_by($class, $params = array()); |
|
| 30 | 30 | |
| 31 | 31 | /** |
| 32 | 32 | * Saves a new model of the provided class with the given data. |
@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | * |
| 37 | 37 | * @return Model|WP_Error |
| 38 | 38 | */ |
| 39 | - public function create( $class, $data = array() ); |
|
| 39 | + public function create($class, $data = array()); |
|
| 40 | 40 | |
| 41 | 41 | /** |
| 42 | 42 | * Updates a model with its latest data. |
@@ -45,7 +45,7 @@ discard block |
||
| 45 | 45 | * |
| 46 | 46 | * @return Model|WP_Error |
| 47 | 47 | */ |
| 48 | - public function persist( Model $model ); |
|
| 48 | + public function persist(Model $model); |
|
| 49 | 49 | |
| 50 | 50 | /** |
| 51 | 51 | * Delete the provided Model. |
@@ -55,7 +55,7 @@ discard block |
||
| 55 | 55 | * |
| 56 | 56 | * @return Model|WP_Error |
| 57 | 57 | */ |
| 58 | - public function delete( Model $model, $force = false ); |
|
| 58 | + public function delete(Model $model, $force = false); |
|
| 59 | 59 | |
| 60 | 60 | /** |
| 61 | 61 | * Frees all currently managed models from the EntityManager. |
@@ -41,11 +41,11 @@ discard block |
||
| 41 | 41 | * @param array $elements |
| 42 | 42 | * @param array $config |
| 43 | 43 | */ |
| 44 | - public function __construct( array $elements = array(), array $config = array() ) { |
|
| 45 | - $this->parse_config( $config ); |
|
| 44 | + public function __construct(array $elements = array(), array $config = array()) { |
|
| 45 | + $this->parse_config($config); |
|
| 46 | 46 | |
| 47 | - foreach ( $elements as $element ) { |
|
| 48 | - $this->add( $element ); |
|
| 47 | + foreach ($elements as $element) { |
|
| 48 | + $this->add($element); |
|
| 49 | 49 | } |
| 50 | 50 | } |
| 51 | 51 | |
@@ -56,12 +56,12 @@ discard block |
||
| 56 | 56 | * |
| 57 | 57 | * @throws RuntimeException |
| 58 | 58 | */ |
| 59 | - public function add( $element ) { |
|
| 60 | - if ( $this->model && is_array( $element ) ) { |
|
| 61 | - $element = new $this->model( $element ); |
|
| 59 | + public function add($element) { |
|
| 60 | + if ($this->model && is_array($element)) { |
|
| 61 | + $element = new $this->model($element); |
|
| 62 | 62 | } |
| 63 | 63 | |
| 64 | - if ( $this->model && ! ( $element instanceof $this->model ) ) { |
|
| 64 | + if ($this->model && !($element instanceof $this->model)) { |
|
| 65 | 65 | throw new RuntimeException; |
| 66 | 66 | } |
| 67 | 67 | |
@@ -75,8 +75,8 @@ discard block |
||
| 75 | 75 | * |
| 76 | 76 | * @return mixed |
| 77 | 77 | */ |
| 78 | - public function at( $index ) { |
|
| 79 | - return isset( $this->elements[ $index ] ) ? $this->elements[ $index ] : null; |
|
| 78 | + public function at($index) { |
|
| 79 | + return isset($this->elements[$index]) ? $this->elements[$index] : null; |
|
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | /** |
@@ -85,14 +85,14 @@ discard block |
||
| 85 | 85 | * @return mixed |
| 86 | 86 | */ |
| 87 | 87 | public function current() { |
| 88 | - return $this->at( $this->position ); |
|
| 88 | + return $this->at($this->position); |
|
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | /** |
| 92 | 92 | * Move forward to next element. |
| 93 | 93 | */ |
| 94 | 94 | public function next() { |
| 95 | - $this->position ++; |
|
| 95 | + $this->position++; |
|
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | /** |
@@ -110,7 +110,7 @@ discard block |
||
| 110 | 110 | * @return bool |
| 111 | 111 | */ |
| 112 | 112 | public function valid() { |
| 113 | - return isset( $this->elements[ $this->position ] ); |
|
| 113 | + return isset($this->elements[$this->position]); |
|
| 114 | 114 | } |
| 115 | 115 | |
| 116 | 116 | /** |
@@ -126,7 +126,7 @@ discard block |
||
| 126 | 126 | * @return int |
| 127 | 127 | */ |
| 128 | 128 | public function count() { |
| 129 | - return count( $this->elements ); |
|
| 129 | + return count($this->elements); |
|
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | /** |
@@ -136,11 +136,11 @@ discard block |
||
| 136 | 136 | * |
| 137 | 137 | * @throws LogicException |
| 138 | 138 | */ |
| 139 | - protected function parse_config( array $config ) { |
|
| 140 | - if ( isset( $config['model'] ) ) { |
|
| 139 | + protected function parse_config(array $config) { |
|
| 140 | + if (isset($config['model'])) { |
|
| 141 | 141 | $model = $config['model']; |
| 142 | 142 | |
| 143 | - if ( ! is_subclass_of( $model, 'Intraxia\Jaxion\Axolotl\Model' ) ) { |
|
| 143 | + if (!is_subclass_of($model, 'Intraxia\Jaxion\Axolotl\Model')) { |
|
| 144 | 144 | throw new LogicException; |
| 145 | 145 | } |
| 146 | 146 | |
@@ -154,8 +154,8 @@ discard block |
||
| 154 | 154 | * @return array |
| 155 | 155 | */ |
| 156 | 156 | public function serialize() { |
| 157 | - return array_map(function( $element ) { |
|
| 158 | - if ( $element instanceof Serializes ) { |
|
| 157 | + return array_map(function($element) { |
|
| 158 | + if ($element instanceof Serializes) { |
|
| 159 | 159 | return $element->serialize(); |
| 160 | 160 | } |
| 161 | 161 | |
@@ -106,16 +106,16 @@ discard block |
||
| 106 | 106 | * |
| 107 | 107 | * @param array <string, mixed> $attributes |
| 108 | 108 | */ |
| 109 | - public function __construct( array $attributes = array() ) { |
|
| 109 | + public function __construct(array $attributes = array()) { |
|
| 110 | 110 | $this->maybe_boot(); |
| 111 | 111 | $this->sync_original(); |
| 112 | 112 | |
| 113 | - if ( $this->uses_wp_object() ) { |
|
| 113 | + if ($this->uses_wp_object()) { |
|
| 114 | 114 | $this->create_wp_object(); |
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | $this->unguard(); |
| 118 | - $this->refresh( $attributes ); |
|
| 118 | + $this->refresh($attributes); |
|
| 119 | 119 | $this->reguard(); |
| 120 | 120 | } |
| 121 | 121 | |
@@ -129,10 +129,10 @@ discard block |
||
| 129 | 129 | * |
| 130 | 130 | * @return $this |
| 131 | 131 | */ |
| 132 | - public function refresh( array $attributes ) { |
|
| 132 | + public function refresh(array $attributes) { |
|
| 133 | 133 | $this->clear(); |
| 134 | 134 | |
| 135 | - return $this->merge( $attributes ); |
|
| 135 | + return $this->merge($attributes); |
|
| 136 | 136 | } |
| 137 | 137 | |
| 138 | 138 | /** |
@@ -142,9 +142,9 @@ discard block |
||
| 142 | 142 | * |
| 143 | 143 | * @return $this |
| 144 | 144 | */ |
| 145 | - public function merge( array $attributes ) { |
|
| 146 | - foreach ( $attributes as $name => $value ) { |
|
| 147 | - $this->set_attribute( $name, $value ); |
|
| 145 | + public function merge(array $attributes) { |
|
| 146 | + foreach ($attributes as $name => $value) { |
|
| 147 | + $this->set_attribute($name, $value); |
|
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | return $this; |
@@ -159,7 +159,7 @@ discard block |
||
| 159 | 159 | * @return array |
| 160 | 160 | */ |
| 161 | 161 | public function get_table_attributes() { |
| 162 | - return $this->attributes[ self::TABLE_KEY ]; |
|
| 162 | + return $this->attributes[self::TABLE_KEY]; |
|
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | /** |
@@ -168,7 +168,7 @@ discard block |
||
| 168 | 168 | * @return array |
| 169 | 169 | */ |
| 170 | 170 | public function get_original_table_attributes() { |
| 171 | - return $this->original[ self::TABLE_KEY ]; |
|
| 171 | + return $this->original[self::TABLE_KEY]; |
|
| 172 | 172 | } |
| 173 | 173 | |
| 174 | 174 | /** |
@@ -181,11 +181,11 @@ discard block |
||
| 181 | 181 | public function get_changed_table_attributes() { |
| 182 | 182 | $changed = array(); |
| 183 | 183 | |
| 184 | - foreach ( $this->get_table_attributes() as $key => $value ) { |
|
| 185 | - if ( $value !== |
|
| 186 | - $this->get_original_attribute( $key ) |
|
| 184 | + foreach ($this->get_table_attributes() as $key => $value) { |
|
| 185 | + if ($value !== |
|
| 186 | + $this->get_original_attribute($key) |
|
| 187 | 187 | ) { |
| 188 | - $changed[ $key ] = $value; |
|
| 188 | + $changed[$key] = $value; |
|
| 189 | 189 | } |
| 190 | 190 | } |
| 191 | 191 | |
@@ -201,8 +201,8 @@ discard block |
||
| 201 | 201 | * @return false|WP_Post|WP_Term |
| 202 | 202 | */ |
| 203 | 203 | public function get_underlying_wp_object() { |
| 204 | - if ( isset( $this->attributes[ self::OBJECT_KEY ] ) ) { |
|
| 205 | - return $this->attributes[ self::OBJECT_KEY ]; |
|
| 204 | + if (isset($this->attributes[self::OBJECT_KEY])) { |
|
| 205 | + return $this->attributes[self::OBJECT_KEY]; |
|
| 206 | 206 | } |
| 207 | 207 | |
| 208 | 208 | return false; |
@@ -214,7 +214,7 @@ discard block |
||
| 214 | 214 | * @return WP_Post |
| 215 | 215 | */ |
| 216 | 216 | public function get_original_underlying_wp_object() { |
| 217 | - return $this->original[ self::OBJECT_KEY ]; |
|
| 217 | + return $this->original[self::OBJECT_KEY]; |
|
| 218 | 218 | } |
| 219 | 219 | |
| 220 | 220 | /** |
@@ -227,11 +227,11 @@ discard block |
||
| 227 | 227 | public function get_changed_wp_object_attributes() { |
| 228 | 228 | $changed = array(); |
| 229 | 229 | |
| 230 | - foreach ( $this->get_wp_object_keys() as $key ) { |
|
| 231 | - if ( $this->get_attribute( $key ) !== |
|
| 232 | - $this->get_original_attribute( $key ) |
|
| 230 | + foreach ($this->get_wp_object_keys() as $key) { |
|
| 231 | + if ($this->get_attribute($key) !== |
|
| 232 | + $this->get_original_attribute($key) |
|
| 233 | 233 | ) { |
| 234 | - $changed[ $key ] = $this->get_attribute( $key ); |
|
| 234 | + $changed[$key] = $this->get_attribute($key); |
|
| 235 | 235 | } |
| 236 | 236 | } |
| 237 | 237 | |
@@ -246,8 +246,8 @@ discard block |
||
| 246 | 246 | * @param string $name |
| 247 | 247 | * @param mixed $value |
| 248 | 248 | */ |
| 249 | - public function __set( $name, $value ) { |
|
| 250 | - $this->set_attribute( $name, $value ); |
|
| 249 | + public function __set($name, $value) { |
|
| 250 | + $this->set_attribute($name, $value); |
|
| 251 | 251 | } |
| 252 | 252 | |
| 253 | 253 | /** |
@@ -264,23 +264,23 @@ discard block |
||
| 264 | 264 | * |
| 265 | 265 | * @throws GuardedPropertyException |
| 266 | 266 | */ |
| 267 | - public function set_attribute( $name, $value ) { |
|
| 268 | - if ( self::OBJECT_KEY === $name ) { |
|
| 269 | - return $this->override_wp_object( $value ); |
|
| 267 | + public function set_attribute($name, $value) { |
|
| 268 | + if (self::OBJECT_KEY === $name) { |
|
| 269 | + return $this->override_wp_object($value); |
|
| 270 | 270 | } |
| 271 | 271 | |
| 272 | - if ( self::TABLE_KEY === $name ) { |
|
| 273 | - return $this->override_table( $value ); |
|
| 272 | + if (self::TABLE_KEY === $name) { |
|
| 273 | + return $this->override_table($value); |
|
| 274 | 274 | } |
| 275 | 275 | |
| 276 | - if ( ! $this->is_fillable( $name ) ) { |
|
| 276 | + if (!$this->is_fillable($name)) { |
|
| 277 | 277 | throw new GuardedPropertyException; |
| 278 | 278 | } |
| 279 | 279 | |
| 280 | - if ( $method = $this->has_map_method( $name ) ) { |
|
| 281 | - $this->attributes[ self::OBJECT_KEY ]->{$this->{$method}()} = $value; |
|
| 280 | + if ($method = $this->has_map_method($name)) { |
|
| 281 | + $this->attributes[self::OBJECT_KEY]->{$this->{$method}()} = $value; |
|
| 282 | 282 | } else { |
| 283 | - $this->attributes[ self::TABLE_KEY ][ $name ] = $value; |
|
| 283 | + $this->attributes[self::TABLE_KEY][$name] = $value; |
|
| 284 | 284 | } |
| 285 | 285 | |
| 286 | 286 | return $this; |
@@ -292,11 +292,11 @@ discard block |
||
| 292 | 292 | * @return array |
| 293 | 293 | */ |
| 294 | 294 | public function get_attribute_keys() { |
| 295 | - if ( isset( self::$memo[ get_called_class() ][ __METHOD__ ] ) ) { |
|
| 296 | - return self::$memo[ get_called_class() ][ __METHOD__ ]; |
|
| 295 | + if (isset(self::$memo[get_called_class()][__METHOD__])) { |
|
| 296 | + return self::$memo[get_called_class()][__METHOD__]; |
|
| 297 | 297 | } |
| 298 | 298 | |
| 299 | - return self::$memo[ get_called_class() ][ __METHOD__ ] |
|
| 299 | + return self::$memo[get_called_class()][__METHOD__] |
|
| 300 | 300 | = array_merge( |
| 301 | 301 | $this->fillable, |
| 302 | 302 | $this->guarded, |
@@ -310,21 +310,21 @@ discard block |
||
| 310 | 310 | * @return array |
| 311 | 311 | */ |
| 312 | 312 | public function get_table_keys() { |
| 313 | - if ( isset( self::$memo[ get_called_class() ][ __METHOD__ ] ) ) { |
|
| 314 | - return self::$memo[ get_called_class() ][ __METHOD__ ]; |
|
| 313 | + if (isset(self::$memo[get_called_class()][__METHOD__])) { |
|
| 314 | + return self::$memo[get_called_class()][__METHOD__]; |
|
| 315 | 315 | } |
| 316 | 316 | |
| 317 | 317 | $keys = array(); |
| 318 | 318 | |
| 319 | - foreach ( $this->get_attribute_keys() as $key ) { |
|
| 320 | - if ( ! $this->has_map_method( $key ) && |
|
| 321 | - ! $this->has_compute_method( $key ) |
|
| 319 | + foreach ($this->get_attribute_keys() as $key) { |
|
| 320 | + if (!$this->has_map_method($key) && |
|
| 321 | + !$this->has_compute_method($key) |
|
| 322 | 322 | ) { |
| 323 | 323 | $keys[] = $key; |
| 324 | 324 | } |
| 325 | 325 | } |
| 326 | 326 | |
| 327 | - return self::$memo[ get_called_class() ][ __METHOD__ ] = $keys; |
|
| 327 | + return self::$memo[get_called_class()][__METHOD__] = $keys; |
|
| 328 | 328 | } |
| 329 | 329 | |
| 330 | 330 | /** |
@@ -333,19 +333,19 @@ discard block |
||
| 333 | 333 | * @return array |
| 334 | 334 | */ |
| 335 | 335 | public function get_wp_object_keys() { |
| 336 | - if ( isset( self::$memo[ get_called_class() ][ __METHOD__ ] ) ) { |
|
| 337 | - return self::$memo[ get_called_class() ][ __METHOD__ ]; |
|
| 336 | + if (isset(self::$memo[get_called_class()][__METHOD__])) { |
|
| 337 | + return self::$memo[get_called_class()][__METHOD__]; |
|
| 338 | 338 | } |
| 339 | 339 | |
| 340 | 340 | $keys = array(); |
| 341 | 341 | |
| 342 | - foreach ( $this->get_attribute_keys() as $key ) { |
|
| 343 | - if ( $this->has_map_method( $key ) ) { |
|
| 342 | + foreach ($this->get_attribute_keys() as $key) { |
|
| 343 | + if ($this->has_map_method($key)) { |
|
| 344 | 344 | $keys[] = $key; |
| 345 | 345 | } |
| 346 | 346 | } |
| 347 | 347 | |
| 348 | - return self::$memo[ get_called_class() ][ __METHOD__ ] = $keys; |
|
| 348 | + return self::$memo[get_called_class()][__METHOD__] = $keys; |
|
| 349 | 349 | } |
| 350 | 350 | |
| 351 | 351 | /** |
@@ -354,19 +354,19 @@ discard block |
||
| 354 | 354 | * @return array |
| 355 | 355 | */ |
| 356 | 356 | public function get_computed_keys() { |
| 357 | - if ( isset( self::$memo[ get_called_class() ][ __METHOD__ ] ) ) { |
|
| 358 | - return self::$memo[ get_called_class() ][ __METHOD__ ]; |
|
| 357 | + if (isset(self::$memo[get_called_class()][__METHOD__])) { |
|
| 358 | + return self::$memo[get_called_class()][__METHOD__]; |
|
| 359 | 359 | } |
| 360 | 360 | |
| 361 | 361 | $keys = array(); |
| 362 | 362 | |
| 363 | - foreach ( $this->get_attribute_keys() as $key ) { |
|
| 364 | - if ( $this->has_compute_method( $key ) ) { |
|
| 363 | + foreach ($this->get_attribute_keys() as $key) { |
|
| 364 | + if ($this->has_compute_method($key)) { |
|
| 365 | 365 | $keys[] = $key; |
| 366 | 366 | } |
| 367 | 367 | } |
| 368 | 368 | |
| 369 | - return self::$memo[ get_called_class() ][ __METHOD__ ] = $keys; |
|
| 369 | + return self::$memo[get_called_class()][__METHOD__] = $keys; |
|
| 370 | 370 | } |
| 371 | 371 | |
| 372 | 372 | /** |
@@ -377,32 +377,32 @@ discard block |
||
| 377 | 377 | public function serialize() { |
| 378 | 378 | $attributes = array(); |
| 379 | 379 | |
| 380 | - if ( $this->visible ) { |
|
| 380 | + if ($this->visible) { |
|
| 381 | 381 | // If visible attributes are set, we'll only reveal those. |
| 382 | - foreach ( $this->visible as $key ) { |
|
| 383 | - $attributes[ $key ] = $this->get_attribute( $key ); |
|
| 382 | + foreach ($this->visible as $key) { |
|
| 383 | + $attributes[$key] = $this->get_attribute($key); |
|
| 384 | 384 | } |
| 385 | - } elseif ( $this->hidden ) { |
|
| 385 | + } elseif ($this->hidden) { |
|
| 386 | 386 | // If hidden attributes are set, we'll grab everything and hide those. |
| 387 | - foreach ( $this->get_attribute_keys() as $key ) { |
|
| 388 | - if ( ! in_array( $key, $this->hidden ) ) { |
|
| 389 | - $attributes[ $key ] = $this->get_attribute( $key ); |
|
| 387 | + foreach ($this->get_attribute_keys() as $key) { |
|
| 388 | + if (!in_array($key, $this->hidden)) { |
|
| 389 | + $attributes[$key] = $this->get_attribute($key); |
|
| 390 | 390 | } |
| 391 | 391 | } |
| 392 | 392 | } else { |
| 393 | 393 | // If nothing is hidden/visible, we'll grab and reveal everything. |
| 394 | - foreach ( $this->get_attribute_keys() as $key ) { |
|
| 395 | - $attributes[ $key ] = $this->get_attribute( $key ); |
|
| 394 | + foreach ($this->get_attribute_keys() as $key) { |
|
| 395 | + $attributes[$key] = $this->get_attribute($key); |
|
| 396 | 396 | } |
| 397 | 397 | } |
| 398 | 398 | |
| 399 | - return array_map( function ( $attribute ) { |
|
| 400 | - if ( $attribute instanceof Serializes ) { |
|
| 399 | + return array_map(function($attribute) { |
|
| 400 | + if ($attribute instanceof Serializes) { |
|
| 401 | 401 | return $attribute->serialize(); |
| 402 | 402 | } |
| 403 | 403 | |
| 404 | 404 | return $attribute; |
| 405 | - }, $attributes ); |
|
| 405 | + }, $attributes); |
|
| 406 | 406 | } |
| 407 | 407 | |
| 408 | 408 | /** |
@@ -413,8 +413,8 @@ discard block |
||
| 413 | 413 | public function sync_original() { |
| 414 | 414 | $this->original = $this->attributes; |
| 415 | 415 | |
| 416 | - if ( $this->attributes[ self::OBJECT_KEY ] ) { |
|
| 417 | - $this->original[ self::OBJECT_KEY ] = clone $this->attributes[ self::OBJECT_KEY ]; |
|
| 416 | + if ($this->attributes[self::OBJECT_KEY]) { |
|
| 417 | + $this->original[self::OBJECT_KEY] = clone $this->attributes[self::OBJECT_KEY]; |
|
| 418 | 418 | } |
| 419 | 419 | |
| 420 | 420 | return $this; |
@@ -429,24 +429,24 @@ discard block |
||
| 429 | 429 | * |
| 430 | 430 | * @return bool |
| 431 | 431 | */ |
| 432 | - private function is_fillable( $name ) { |
|
| 432 | + private function is_fillable($name) { |
|
| 433 | 433 | // If this model isn't guarded, everything is fillable. |
| 434 | - if ( ! $this->is_guarded ) { |
|
| 434 | + if (!$this->is_guarded) { |
|
| 435 | 435 | return true; |
| 436 | 436 | } |
| 437 | 437 | |
| 438 | 438 | // If it's in the fillable array, then it's fillable. |
| 439 | - if ( in_array( $name, $this->fillable ) ) { |
|
| 439 | + if (in_array($name, $this->fillable)) { |
|
| 440 | 440 | return true; |
| 441 | 441 | } |
| 442 | 442 | |
| 443 | 443 | // If it's explicitly guarded, then it's not fillable. |
| 444 | - if ( in_array( $name, $this->guarded ) ) { |
|
| 444 | + if (in_array($name, $this->guarded)) { |
|
| 445 | 445 | return false; |
| 446 | 446 | } |
| 447 | 447 | |
| 448 | 448 | // If fillable hasn't been defined, then everything else fillable. |
| 449 | - return ! $this->fillable; |
|
| 449 | + return !$this->fillable; |
|
| 450 | 450 | } |
| 451 | 451 | |
| 452 | 452 | /** |
@@ -458,8 +458,8 @@ discard block |
||
| 458 | 458 | * |
| 459 | 459 | * @return $this |
| 460 | 460 | */ |
| 461 | - private function override_wp_object( $value ) { |
|
| 462 | - $this->attributes[ self::OBJECT_KEY ] = $this->set_wp_object_constants( $value ); |
|
| 461 | + private function override_wp_object($value) { |
|
| 462 | + $this->attributes[self::OBJECT_KEY] = $this->set_wp_object_constants($value); |
|
| 463 | 463 | |
| 464 | 464 | return $this; |
| 465 | 465 | } |
@@ -471,8 +471,8 @@ discard block |
||
| 471 | 471 | * |
| 472 | 472 | * @return $this |
| 473 | 473 | */ |
| 474 | - private function override_table( array $value ) { |
|
| 475 | - $this->attributes[ self::TABLE_KEY ] = $value; |
|
| 474 | + private function override_table(array $value) { |
|
| 475 | + $this->attributes[self::TABLE_KEY] = $value; |
|
| 476 | 476 | |
| 477 | 477 | return $this; |
| 478 | 478 | } |
@@ -486,19 +486,19 @@ discard block |
||
| 486 | 486 | * @throws LogicException |
| 487 | 487 | */ |
| 488 | 488 | private function create_wp_object() { |
| 489 | - switch ( true ) { |
|
| 489 | + switch (true) { |
|
| 490 | 490 | case $this instanceof UsesWordPressPost: |
| 491 | - $object = new WP_Post( (object) array() ); |
|
| 491 | + $object = new WP_Post((object) array()); |
|
| 492 | 492 | break; |
| 493 | 493 | case $this instanceof UsesWordPressTerm: |
| 494 | - $object = new WP_Term( (object) array() ); |
|
| 494 | + $object = new WP_Term((object) array()); |
|
| 495 | 495 | break; |
| 496 | 496 | default: |
| 497 | 497 | throw new LogicException; |
| 498 | 498 | break; |
| 499 | 499 | } |
| 500 | 500 | |
| 501 | - $this->attributes[ self::OBJECT_KEY ] = $this->set_wp_object_constants( $object ); |
|
| 501 | + $this->attributes[self::OBJECT_KEY] = $this->set_wp_object_constants($object); |
|
| 502 | 502 | } |
| 503 | 503 | |
| 504 | 504 | /** |
@@ -512,12 +512,12 @@ discard block |
||
| 512 | 512 | * |
| 513 | 513 | * @return object |
| 514 | 514 | */ |
| 515 | - protected function set_wp_object_constants( $object ) { |
|
| 516 | - if ( $this instanceof UsesWordPressPost ) { |
|
| 515 | + protected function set_wp_object_constants($object) { |
|
| 516 | + if ($this instanceof UsesWordPressPost) { |
|
| 517 | 517 | $object->post_type = $this::get_post_type(); |
| 518 | 518 | } |
| 519 | 519 | |
| 520 | - if ( $this instanceof UsesWordPressTerm ) { |
|
| 520 | + if ($this instanceof UsesWordPressTerm) { |
|
| 521 | 521 | $object->taxonomy = $this::get_taxonomy(); |
| 522 | 522 | } |
| 523 | 523 | |
@@ -533,8 +533,8 @@ discard block |
||
| 533 | 533 | * |
| 534 | 534 | * @return mixed |
| 535 | 535 | */ |
| 536 | - public function __get( $name ) { |
|
| 537 | - return $this->get_attribute( $name ); |
|
| 536 | + public function __get($name) { |
|
| 537 | + return $this->get_attribute($name); |
|
| 538 | 538 | } |
| 539 | 539 | |
| 540 | 540 | /** |
@@ -546,17 +546,17 @@ discard block |
||
| 546 | 546 | * |
| 547 | 547 | * @throws PropertyDoesNotExistException If property isn't found. |
| 548 | 548 | */ |
| 549 | - public function get_attribute( $name ) { |
|
| 550 | - if ( $method = $this->has_map_method( $name ) ) { |
|
| 551 | - $value = $this->attributes[ self::OBJECT_KEY ]->{$this->{$method}()}; |
|
| 552 | - } elseif ( $method = $this->has_compute_method( $name ) ) { |
|
| 549 | + public function get_attribute($name) { |
|
| 550 | + if ($method = $this->has_map_method($name)) { |
|
| 551 | + $value = $this->attributes[self::OBJECT_KEY]->{$this->{$method}()}; |
|
| 552 | + } elseif ($method = $this->has_compute_method($name)) { |
|
| 553 | 553 | $value = $this->{$method}(); |
| 554 | 554 | } else { |
| 555 | - if ( ! isset( $this->attributes[ self::TABLE_KEY ][ $name ] ) ) { |
|
| 556 | - throw new PropertyDoesNotExistException( $name ); |
|
| 555 | + if (!isset($this->attributes[self::TABLE_KEY][$name])) { |
|
| 556 | + throw new PropertyDoesNotExistException($name); |
|
| 557 | 557 | } |
| 558 | 558 | |
| 559 | - $value = $this->attributes[ self::TABLE_KEY ][ $name ]; |
|
| 559 | + $value = $this->attributes[self::TABLE_KEY][$name]; |
|
| 560 | 560 | } |
| 561 | 561 | |
| 562 | 562 | return $value; |
@@ -571,10 +571,10 @@ discard block |
||
| 571 | 571 | * |
| 572 | 572 | * @throws PropertyDoesNotExistException If property isn't found. |
| 573 | 573 | */ |
| 574 | - public function get_original_attribute( $name ) { |
|
| 575 | - $original = new static( $this->original ); |
|
| 574 | + public function get_original_attribute($name) { |
|
| 575 | + $original = new static($this->original); |
|
| 576 | 576 | |
| 577 | - return $original->get_attribute( $name ); |
|
| 577 | + return $original->get_attribute($name); |
|
| 578 | 578 | } |
| 579 | 579 | |
| 580 | 580 | /** |
@@ -586,11 +586,11 @@ discard block |
||
| 586 | 586 | * @throws LogicException |
| 587 | 587 | */ |
| 588 | 588 | public function get_primary_id() { |
| 589 | - if ( $this instanceof UsesWordPressPost ) { |
|
| 589 | + if ($this instanceof UsesWordPressPost) { |
|
| 590 | 590 | return $this->get_underlying_wp_object()->ID; |
| 591 | 591 | } |
| 592 | 592 | |
| 593 | - if ( $this instanceof UsesWordPressTerm ) { |
|
| 593 | + if ($this instanceof UsesWordPressTerm) { |
|
| 594 | 594 | return $this->get_underlying_wp_object()->term_id; |
| 595 | 595 | } |
| 596 | 596 | |
@@ -609,8 +609,8 @@ discard block |
||
| 609 | 609 | * |
| 610 | 610 | * @return false|string |
| 611 | 611 | */ |
| 612 | - protected function has_map_method( $name ) { |
|
| 613 | - if ( method_exists( $this, $method = "map_{$name}" ) ) { |
|
| 612 | + protected function has_map_method($name) { |
|
| 613 | + if (method_exists($this, $method = "map_{$name}")) { |
|
| 614 | 614 | return $method; |
| 615 | 615 | } |
| 616 | 616 | |
@@ -627,8 +627,8 @@ discard block |
||
| 627 | 627 | * |
| 628 | 628 | * @return false|string |
| 629 | 629 | */ |
| 630 | - protected function has_compute_method( $name ) { |
|
| 631 | - if ( method_exists( $this, $method = "compute_{$name}" ) ) { |
|
| 630 | + protected function has_compute_method($name) { |
|
| 631 | + if (method_exists($this, $method = "compute_{$name}")) { |
|
| 632 | 632 | return $method; |
| 633 | 633 | } |
| 634 | 634 | |
@@ -649,10 +649,10 @@ discard block |
||
| 649 | 649 | $this->get_wp_object_keys() |
| 650 | 650 | ); |
| 651 | 651 | |
| 652 | - foreach ( $keys as $key ) { |
|
| 652 | + foreach ($keys as $key) { |
|
| 653 | 653 | try { |
| 654 | - $this->set_attribute( $key, null ); |
|
| 655 | - } catch ( GuardedPropertyException $e ) { |
|
| 654 | + $this->set_attribute($key, null); |
|
| 655 | + } catch (GuardedPropertyException $e) { |
|
| 656 | 656 | // We won't clear out guarded attributes. |
| 657 | 657 | } |
| 658 | 658 | } |
@@ -686,13 +686,13 @@ discard block |
||
| 686 | 686 | * @return array |
| 687 | 687 | */ |
| 688 | 688 | protected function get_compute_methods() { |
| 689 | - $methods = get_class_methods( get_called_class() ); |
|
| 690 | - $methods = array_filter( $methods, function ( $method ) { |
|
| 691 | - return strrpos( $method, 'compute_', - strlen( $method ) ) !== false; |
|
| 689 | + $methods = get_class_methods(get_called_class()); |
|
| 690 | + $methods = array_filter($methods, function($method) { |
|
| 691 | + return strrpos($method, 'compute_', - strlen($method)) !== false; |
|
| 692 | 692 | } ); |
| 693 | - $methods = array_map( function ( $method ) { |
|
| 694 | - return substr( $method, strlen( 'compute_' ) ); |
|
| 695 | - }, $methods ); |
|
| 693 | + $methods = array_map(function($method) { |
|
| 694 | + return substr($method, strlen('compute_')); |
|
| 695 | + }, $methods); |
|
| 696 | 696 | |
| 697 | 697 | return $methods; |
| 698 | 698 | } |
@@ -701,8 +701,8 @@ discard block |
||
| 701 | 701 | * Sets up the memo array for the creating model. |
| 702 | 702 | */ |
| 703 | 703 | private function maybe_boot() { |
| 704 | - if ( ! isset( self::$memo[ get_called_class() ] ) ) { |
|
| 705 | - self::$memo[ get_called_class() ] = array(); |
|
| 704 | + if (!isset(self::$memo[get_called_class()])) { |
|
| 705 | + self::$memo[get_called_class()] = array(); |
|
| 706 | 706 | } |
| 707 | 707 | } |
| 708 | 708 | |