@@ -79,7 +79,7 @@ discard block |
||
| 79 | 79 | */ |
| 80 | 80 | public function hasField(string $name): bool |
| 81 | 81 | { |
| 82 | - if (!array_key_exists($name, $this->fields)) { |
|
| 82 | + if (!array_key_exists($name, $this->fields)){ |
|
| 83 | 83 | return false; |
| 84 | 84 | } |
| 85 | 85 | |
@@ -95,14 +95,14 @@ discard block |
||
| 95 | 95 | */ |
| 96 | 96 | public function setField(string $name, $value, bool $filter = true): void |
| 97 | 97 | { |
| 98 | - if ($value instanceof ValueInterface) { |
|
| 98 | + if ($value instanceof ValueInterface){ |
|
| 99 | 99 | //In case of non scalar values filters must be bypassed (check accessor compatibility?) |
| 100 | 100 | $this->fields[$name] = clone $value; |
| 101 | 101 | |
| 102 | 102 | return; |
| 103 | 103 | } |
| 104 | 104 | |
| 105 | - if (!$filter || (is_null($value) && $this->isNullable($name))) { |
|
| 105 | + if (!$filter || (is_null($value) && $this->isNullable($name))){ |
|
| 106 | 106 | //Bypassing all filters |
| 107 | 107 | $this->fields[$name] = $value; |
| 108 | 108 | |
@@ -112,10 +112,10 @@ discard block |
||
| 112 | 112 | //Checking if field have accessor |
| 113 | 113 | $accessor = $this->getMutator($name, ModelSchema::MUTATOR_ACCESSOR); |
| 114 | 114 | |
| 115 | - if ($accessor !== null) { |
|
| 115 | + if ($accessor !== null){ |
|
| 116 | 116 | //Setting value thought associated accessor |
| 117 | 117 | $this->thoughValue($accessor, $name, $value); |
| 118 | - } else { |
|
| 118 | + }else{ |
|
| 119 | 119 | //Setting value thought setter filter (if any) |
| 120 | 120 | $this->setMutated($name, $value); |
| 121 | 121 | } |
@@ -132,7 +132,7 @@ discard block |
||
| 132 | 132 | { |
| 133 | 133 | $value = $this->hasField($name) ? $this->fields[$name] : $default; |
| 134 | 134 | |
| 135 | - if ($value instanceof ValueInterface || (is_null($value) && $this->isNullable($name))) { |
|
| 135 | + if ($value instanceof ValueInterface || (is_null($value) && $this->isNullable($name))){ |
|
| 136 | 136 | //Direct access to value when value is accessor or null and declared as nullable |
| 137 | 137 | return $value; |
| 138 | 138 | } |
@@ -140,7 +140,7 @@ discard block |
||
| 140 | 140 | //Checking if field have accessor (decorator) |
| 141 | 141 | $accessor = $this->getMutator($name, ModelSchema::MUTATOR_ACCESSOR); |
| 142 | 142 | |
| 143 | - if (!empty($accessor)) { |
|
| 143 | + if (!empty($accessor)){ |
|
| 144 | 144 | return $this->fields[$name] = $this->createValue($accessor, $name, $value); |
| 145 | 145 | } |
| 146 | 146 | |
@@ -163,15 +163,15 @@ discard block |
||
| 163 | 163 | */ |
| 164 | 164 | public function setFields($fields = [], bool $all = false) |
| 165 | 165 | { |
| 166 | - if (!is_array($fields) && !$fields instanceof \Traversable) { |
|
| 166 | + if (!is_array($fields) && !$fields instanceof \Traversable){ |
|
| 167 | 167 | return $this; |
| 168 | 168 | } |
| 169 | 169 | |
| 170 | - foreach ($fields as $name => $value) { |
|
| 171 | - if ($all || $this->isFillable($name)) { |
|
| 172 | - try { |
|
| 170 | + foreach ($fields as $name => $value){ |
|
| 171 | + if ($all || $this->isFillable($name)){ |
|
| 172 | + try{ |
|
| 173 | 173 | $this->setField($name, $value, true); |
| 174 | - } catch (AccessExceptionInterface $e) { |
|
| 174 | + }catch (AccessExceptionInterface $e){ |
|
| 175 | 175 | //We are suppressing field setting exceptions |
| 176 | 176 | } |
| 177 | 177 | } |
@@ -192,7 +192,7 @@ discard block |
||
| 192 | 192 | public function getFields(bool $filter = true): array |
| 193 | 193 | { |
| 194 | 194 | $result = []; |
| 195 | - foreach ($this->fields as $name => $field) { |
|
| 195 | + foreach ($this->fields as $name => $field){ |
|
| 196 | 196 | $result[$name] = $this->getField($name, null, $filter); |
| 197 | 197 | } |
| 198 | 198 | |
@@ -259,10 +259,10 @@ discard block |
||
| 259 | 259 | public function getValue(): array |
| 260 | 260 | { |
| 261 | 261 | $result = []; |
| 262 | - foreach ($this->fields as $field => $value) { |
|
| 263 | - if ($value instanceof ValueInterface) { |
|
| 262 | + foreach ($this->fields as $field => $value){ |
|
| 263 | + if ($value instanceof ValueInterface){ |
|
| 264 | 264 | $result[$field] = $value->getValue(); |
| 265 | - } else { |
|
| 265 | + }else{ |
|
| 266 | 266 | $result[$field] = $value; |
| 267 | 267 | } |
| 268 | 268 | } |
@@ -355,9 +355,9 @@ discard block |
||
| 355 | 355 | $value, |
| 356 | 356 | array $context = [] |
| 357 | 357 | ): ValueInterface { |
| 358 | - if (!is_string($type) || !class_exists($type)) { |
|
| 358 | + if (!is_string($type) || !class_exists($type)){ |
|
| 359 | 359 | throw new EntityException( |
| 360 | - "Unable to create accessor for field `{$name}` in " . static::class |
|
| 360 | + "Unable to create accessor for field `{$name}` in ".static::class |
|
| 361 | 361 | ); |
| 362 | 362 | } |
| 363 | 363 | |
@@ -377,10 +377,10 @@ discard block |
||
| 377 | 377 | { |
| 378 | 378 | $getter = $this->getMutator($name, ModelSchema::MUTATOR_GETTER); |
| 379 | 379 | |
| 380 | - if ($filter && !empty($getter)) { |
|
| 381 | - try { |
|
| 380 | + if ($filter && !empty($getter)){ |
|
| 381 | + try{ |
|
| 382 | 382 | return call_user_func($getter, $value); |
| 383 | - } catch (\Exception $e) { |
|
| 383 | + }catch (\Exception $e){ |
|
| 384 | 384 | //Trying to filter null value, every filter must support it |
| 385 | 385 | return call_user_func($getter, null); |
| 386 | 386 | } |
@@ -399,13 +399,13 @@ discard block |
||
| 399 | 399 | { |
| 400 | 400 | $setter = $this->getMutator($name, ModelSchema::MUTATOR_SETTER); |
| 401 | 401 | |
| 402 | - if (!empty($setter)) { |
|
| 403 | - try { |
|
| 402 | + if (!empty($setter)){ |
|
| 403 | + try{ |
|
| 404 | 404 | $this->fields[$name] = call_user_func($setter, $value); |
| 405 | - } catch (\Exception $e) { |
|
| 405 | + }catch (\Exception $e){ |
|
| 406 | 406 | //Exceptional situation, we are choosing to keep original field value |
| 407 | 407 | } |
| 408 | - } else { |
|
| 408 | + }else{ |
|
| 409 | 409 | $this->fields[$name] = $value; |
| 410 | 410 | } |
| 411 | 411 | } |
@@ -419,13 +419,13 @@ discard block |
||
| 419 | 419 | */ |
| 420 | 420 | private function thoughValue($type, string $name, $value): void |
| 421 | 421 | { |
| 422 | - if (array_key_exists($name, $this->fields)) { |
|
| 422 | + if (array_key_exists($name, $this->fields)){ |
|
| 423 | 423 | $field = $this->fields[$name]; |
| 424 | - } else { |
|
| 424 | + }else{ |
|
| 425 | 425 | $field = null; |
| 426 | 426 | } |
| 427 | 427 | |
| 428 | - if (empty($field) || !($field instanceof ValueInterface)) { |
|
| 428 | + if (empty($field) || !($field instanceof ValueInterface)){ |
|
| 429 | 429 | //New field representation |
| 430 | 430 | $field = $this->createValue($type, $name, $value); |
| 431 | 431 | |
@@ -79,7 +79,8 @@ discard block |
||
| 79 | 79 | */ |
| 80 | 80 | public function hasField(string $name): bool |
| 81 | 81 | { |
| 82 | - if (!array_key_exists($name, $this->fields)) { |
|
| 82 | + if (!array_key_exists($name, $this->fields)) |
|
| 83 | + { |
|
| 83 | 84 | return false; |
| 84 | 85 | } |
| 85 | 86 | |
@@ -95,14 +96,16 @@ discard block |
||
| 95 | 96 | */ |
| 96 | 97 | public function setField(string $name, $value, bool $filter = true): void |
| 97 | 98 | { |
| 98 | - if ($value instanceof ValueInterface) { |
|
| 99 | + if ($value instanceof ValueInterface) |
|
| 100 | + { |
|
| 99 | 101 | //In case of non scalar values filters must be bypassed (check accessor compatibility?) |
| 100 | 102 | $this->fields[$name] = clone $value; |
| 101 | 103 | |
| 102 | 104 | return; |
| 103 | 105 | } |
| 104 | 106 | |
| 105 | - if (!$filter || (is_null($value) && $this->isNullable($name))) { |
|
| 107 | + if (!$filter || (is_null($value) && $this->isNullable($name))) |
|
| 108 | + { |
|
| 106 | 109 | //Bypassing all filters |
| 107 | 110 | $this->fields[$name] = $value; |
| 108 | 111 | |
@@ -112,10 +115,13 @@ discard block |
||
| 112 | 115 | //Checking if field have accessor |
| 113 | 116 | $accessor = $this->getMutator($name, ModelSchema::MUTATOR_ACCESSOR); |
| 114 | 117 | |
| 115 | - if ($accessor !== null) { |
|
| 118 | + if ($accessor !== null) |
|
| 119 | + { |
|
| 116 | 120 | //Setting value thought associated accessor |
| 117 | 121 | $this->thoughValue($accessor, $name, $value); |
| 118 | - } else { |
|
| 122 | + } |
|
| 123 | + else |
|
| 124 | + { |
|
| 119 | 125 | //Setting value thought setter filter (if any) |
| 120 | 126 | $this->setMutated($name, $value); |
| 121 | 127 | } |
@@ -132,7 +138,8 @@ discard block |
||
| 132 | 138 | { |
| 133 | 139 | $value = $this->hasField($name) ? $this->fields[$name] : $default; |
| 134 | 140 | |
| 135 | - if ($value instanceof ValueInterface || (is_null($value) && $this->isNullable($name))) { |
|
| 141 | + if ($value instanceof ValueInterface || (is_null($value) && $this->isNullable($name))) |
|
| 142 | + { |
|
| 136 | 143 | //Direct access to value when value is accessor or null and declared as nullable |
| 137 | 144 | return $value; |
| 138 | 145 | } |
@@ -140,7 +147,8 @@ discard block |
||
| 140 | 147 | //Checking if field have accessor (decorator) |
| 141 | 148 | $accessor = $this->getMutator($name, ModelSchema::MUTATOR_ACCESSOR); |
| 142 | 149 | |
| 143 | - if (!empty($accessor)) { |
|
| 150 | + if (!empty($accessor)) |
|
| 151 | + { |
|
| 144 | 152 | return $this->fields[$name] = $this->createValue($accessor, $name, $value); |
| 145 | 153 | } |
| 146 | 154 | |
@@ -163,15 +171,21 @@ discard block |
||
| 163 | 171 | */ |
| 164 | 172 | public function setFields($fields = [], bool $all = false) |
| 165 | 173 | { |
| 166 | - if (!is_array($fields) && !$fields instanceof \Traversable) { |
|
| 174 | + if (!is_array($fields) && !$fields instanceof \Traversable) |
|
| 175 | + { |
|
| 167 | 176 | return $this; |
| 168 | 177 | } |
| 169 | 178 | |
| 170 | - foreach ($fields as $name => $value) { |
|
| 171 | - if ($all || $this->isFillable($name)) { |
|
| 172 | - try { |
|
| 179 | + foreach ($fields as $name => $value) |
|
| 180 | + { |
|
| 181 | + if ($all || $this->isFillable($name)) |
|
| 182 | + { |
|
| 183 | + try |
|
| 184 | + { |
|
| 173 | 185 | $this->setField($name, $value, true); |
| 174 | - } catch (AccessExceptionInterface $e) { |
|
| 186 | + } |
|
| 187 | + catch (AccessExceptionInterface $e) |
|
| 188 | + { |
|
| 175 | 189 | //We are suppressing field setting exceptions |
| 176 | 190 | } |
| 177 | 191 | } |
@@ -192,7 +206,8 @@ discard block |
||
| 192 | 206 | public function getFields(bool $filter = true): array |
| 193 | 207 | { |
| 194 | 208 | $result = []; |
| 195 | - foreach ($this->fields as $name => $field) { |
|
| 209 | + foreach ($this->fields as $name => $field) |
|
| 210 | + { |
|
| 196 | 211 | $result[$name] = $this->getField($name, null, $filter); |
| 197 | 212 | } |
| 198 | 213 | |
@@ -259,10 +274,14 @@ discard block |
||
| 259 | 274 | public function getValue(): array |
| 260 | 275 | { |
| 261 | 276 | $result = []; |
| 262 | - foreach ($this->fields as $field => $value) { |
|
| 263 | - if ($value instanceof ValueInterface) { |
|
| 277 | + foreach ($this->fields as $field => $value) |
|
| 278 | + { |
|
| 279 | + if ($value instanceof ValueInterface) |
|
| 280 | + { |
|
| 264 | 281 | $result[$field] = $value->getValue(); |
| 265 | - } else { |
|
| 282 | + } |
|
| 283 | + else |
|
| 284 | + { |
|
| 266 | 285 | $result[$field] = $value; |
| 267 | 286 | } |
| 268 | 287 | } |
@@ -355,7 +374,8 @@ discard block |
||
| 355 | 374 | $value, |
| 356 | 375 | array $context = [] |
| 357 | 376 | ): ValueInterface { |
| 358 | - if (!is_string($type) || !class_exists($type)) { |
|
| 377 | + if (!is_string($type) || !class_exists($type)) |
|
| 378 | + { |
|
| 359 | 379 | throw new EntityException( |
| 360 | 380 | "Unable to create accessor for field `{$name}` in " . static::class |
| 361 | 381 | ); |
@@ -377,10 +397,14 @@ discard block |
||
| 377 | 397 | { |
| 378 | 398 | $getter = $this->getMutator($name, ModelSchema::MUTATOR_GETTER); |
| 379 | 399 | |
| 380 | - if ($filter && !empty($getter)) { |
|
| 381 | - try { |
|
| 400 | + if ($filter && !empty($getter)) |
|
| 401 | + { |
|
| 402 | + try |
|
| 403 | + { |
|
| 382 | 404 | return call_user_func($getter, $value); |
| 383 | - } catch (\Exception $e) { |
|
| 405 | + } |
|
| 406 | + catch (\Exception $e) |
|
| 407 | + { |
|
| 384 | 408 | //Trying to filter null value, every filter must support it |
| 385 | 409 | return call_user_func($getter, null); |
| 386 | 410 | } |
@@ -399,13 +423,19 @@ discard block |
||
| 399 | 423 | { |
| 400 | 424 | $setter = $this->getMutator($name, ModelSchema::MUTATOR_SETTER); |
| 401 | 425 | |
| 402 | - if (!empty($setter)) { |
|
| 403 | - try { |
|
| 426 | + if (!empty($setter)) |
|
| 427 | + { |
|
| 428 | + try |
|
| 429 | + { |
|
| 404 | 430 | $this->fields[$name] = call_user_func($setter, $value); |
| 405 | - } catch (\Exception $e) { |
|
| 431 | + } |
|
| 432 | + catch (\Exception $e) |
|
| 433 | + { |
|
| 406 | 434 | //Exceptional situation, we are choosing to keep original field value |
| 407 | 435 | } |
| 408 | - } else { |
|
| 436 | + } |
|
| 437 | + else |
|
| 438 | + { |
|
| 409 | 439 | $this->fields[$name] = $value; |
| 410 | 440 | } |
| 411 | 441 | } |
@@ -419,13 +449,17 @@ discard block |
||
| 419 | 449 | */ |
| 420 | 450 | private function thoughValue($type, string $name, $value): void |
| 421 | 451 | { |
| 422 | - if (array_key_exists($name, $this->fields)) { |
|
| 452 | + if (array_key_exists($name, $this->fields)) |
|
| 453 | + { |
|
| 423 | 454 | $field = $this->fields[$name]; |
| 424 | - } else { |
|
| 455 | + } |
|
| 456 | + else |
|
| 457 | + { |
|
| 425 | 458 | $field = null; |
| 426 | 459 | } |
| 427 | 460 | |
| 428 | - if (empty($field) || !($field instanceof ValueInterface)) { |
|
| 461 | + if (empty($field) || !($field instanceof ValueInterface)) |
|
| 462 | + { |
|
| 429 | 463 | //New field representation |
| 430 | 464 | $field = $this->createValue($type, $name, $value); |
| 431 | 465 | |
@@ -92,7 +92,7 @@ discard block |
||
| 92 | 92 | */ |
| 93 | 93 | public function getSecured() |
| 94 | 94 | { |
| 95 | - if ($this->getProperty('secured', true) === '*') { |
|
| 95 | + if ($this->getProperty('secured', true) === '*'){ |
|
| 96 | 96 | return $this->getProperty('secured', true); |
| 97 | 97 | } |
| 98 | 98 | |
@@ -139,8 +139,8 @@ discard block |
||
| 139 | 139 | public function declaredMethods(): array |
| 140 | 140 | { |
| 141 | 141 | $methods = []; |
| 142 | - foreach ($this->getMethods() as $method) { |
|
| 143 | - if ($method->getDeclaringClass()->getName() != $this->getName()) { |
|
| 142 | + foreach ($this->getMethods() as $method){ |
|
| 143 | + if ($method->getDeclaringClass()->getName() != $this->getName()){ |
|
| 144 | 144 | continue; |
| 145 | 145 | } |
| 146 | 146 | |
@@ -174,15 +174,15 @@ discard block |
||
| 174 | 174 | self::MUTATOR_ACCESSOR => [], |
| 175 | 175 | ]; |
| 176 | 176 | |
| 177 | - foreach ((array)$this->getProperty('getters', true) as $field => $filter) { |
|
| 177 | + foreach ((array)$this->getProperty('getters', true) as $field => $filter){ |
|
| 178 | 178 | $mutators[self::MUTATOR_GETTER][$field] = $filter; |
| 179 | 179 | } |
| 180 | 180 | |
| 181 | - foreach ((array)$this->getProperty('setters', true) as $field => $filter) { |
|
| 181 | + foreach ((array)$this->getProperty('setters', true) as $field => $filter){ |
|
| 182 | 182 | $mutators[self::MUTATOR_SETTER][$field] = $filter; |
| 183 | 183 | } |
| 184 | 184 | |
| 185 | - foreach ((array)$this->getProperty('accessors', true) as $field => $filter) { |
|
| 185 | + foreach ((array)$this->getProperty('accessors', true) as $field => $filter){ |
|
| 186 | 186 | $mutators[self::MUTATOR_ACCESSOR][$field] = $filter; |
| 187 | 187 | } |
| 188 | 188 | |
@@ -200,7 +200,7 @@ discard block |
||
| 200 | 200 | */ |
| 201 | 201 | public function getProperty(string $property, bool $merge = false) |
| 202 | 202 | { |
| 203 | - if (isset($this->propertyCache[$property])) { |
|
| 203 | + if (isset($this->propertyCache[$property])){ |
|
| 204 | 204 | //Property merging and trait events are pretty slow |
| 205 | 205 | return $this->propertyCache[$property]; |
| 206 | 206 | } |
@@ -208,27 +208,27 @@ discard block |
||
| 208 | 208 | $properties = $this->reflection->getDefaultProperties(); |
| 209 | 209 | $constants = $this->reflection->getConstants(); |
| 210 | 210 | |
| 211 | - if (isset($properties[$property])) { |
|
| 211 | + if (isset($properties[$property])){ |
|
| 212 | 212 | //Read from default value |
| 213 | 213 | $value = $properties[$property]; |
| 214 | - } elseif (isset($constants[strtoupper($property)])) { |
|
| 214 | + } elseif (isset($constants[strtoupper($property)])){ |
|
| 215 | 215 | //Read from a constant |
| 216 | 216 | $value = $constants[strtoupper($property)]; |
| 217 | - } else { |
|
| 217 | + }else{ |
|
| 218 | 218 | return null; |
| 219 | 219 | } |
| 220 | 220 | |
| 221 | 221 | //Merge with parent value requested |
| 222 | - if ($merge && is_array($value) && !empty($parent = $this->parentReflection())) { |
|
| 222 | + if ($merge && is_array($value) && !empty($parent = $this->parentReflection())){ |
|
| 223 | 223 | $parentValue = $parent->getProperty($property, $merge); |
| 224 | 224 | |
| 225 | - if (is_array($parentValue)) { |
|
| 225 | + if (is_array($parentValue)){ |
|
| 226 | 226 | //Class values prior to parent values |
| 227 | 227 | $value = array_merge($parentValue, $value); |
| 228 | 228 | } |
| 229 | 229 | } |
| 230 | 230 | |
| 231 | - if (!$this->reflection->isSubclassOf(SchematicEntity::class)) { |
|
| 231 | + if (!$this->reflection->isSubclassOf(SchematicEntity::class)){ |
|
| 232 | 232 | return $value; |
| 233 | 233 | } |
| 234 | 234 | |
@@ -245,7 +245,7 @@ discard block |
||
| 245 | 245 | { |
| 246 | 246 | $parentClass = $this->reflection->getParentClass(); |
| 247 | 247 | |
| 248 | - if (!empty($parentClass) && $parentClass->getName() != static::BASE_CLASS) { |
|
| 248 | + if (!empty($parentClass) && $parentClass->getName() != static::BASE_CLASS){ |
|
| 249 | 249 | $parent = clone $this; |
| 250 | 250 | $parent->reflection = $this->getParentClass(); |
| 251 | 251 | |
@@ -92,7 +92,8 @@ discard block |
||
| 92 | 92 | */ |
| 93 | 93 | public function getSecured() |
| 94 | 94 | { |
| 95 | - if ($this->getProperty('secured', true) === '*') { |
|
| 95 | + if ($this->getProperty('secured', true) === '*') |
|
| 96 | + { |
|
| 96 | 97 | return $this->getProperty('secured', true); |
| 97 | 98 | } |
| 98 | 99 | |
@@ -139,8 +140,10 @@ discard block |
||
| 139 | 140 | public function declaredMethods(): array |
| 140 | 141 | { |
| 141 | 142 | $methods = []; |
| 142 | - foreach ($this->getMethods() as $method) { |
|
| 143 | - if ($method->getDeclaringClass()->getName() != $this->getName()) { |
|
| 143 | + foreach ($this->getMethods() as $method) |
|
| 144 | + { |
|
| 145 | + if ($method->getDeclaringClass()->getName() != $this->getName()) |
|
| 146 | + { |
|
| 144 | 147 | continue; |
| 145 | 148 | } |
| 146 | 149 | |
@@ -174,15 +177,18 @@ discard block |
||
| 174 | 177 | self::MUTATOR_ACCESSOR => [], |
| 175 | 178 | ]; |
| 176 | 179 | |
| 177 | - foreach ((array)$this->getProperty('getters', true) as $field => $filter) { |
|
| 180 | + foreach ((array)$this->getProperty('getters', true) as $field => $filter) |
|
| 181 | + { |
|
| 178 | 182 | $mutators[self::MUTATOR_GETTER][$field] = $filter; |
| 179 | 183 | } |
| 180 | 184 | |
| 181 | - foreach ((array)$this->getProperty('setters', true) as $field => $filter) { |
|
| 185 | + foreach ((array)$this->getProperty('setters', true) as $field => $filter) |
|
| 186 | + { |
|
| 182 | 187 | $mutators[self::MUTATOR_SETTER][$field] = $filter; |
| 183 | 188 | } |
| 184 | 189 | |
| 185 | - foreach ((array)$this->getProperty('accessors', true) as $field => $filter) { |
|
| 190 | + foreach ((array)$this->getProperty('accessors', true) as $field => $filter) |
|
| 191 | + { |
|
| 186 | 192 | $mutators[self::MUTATOR_ACCESSOR][$field] = $filter; |
| 187 | 193 | } |
| 188 | 194 | |
@@ -200,7 +206,8 @@ discard block |
||
| 200 | 206 | */ |
| 201 | 207 | public function getProperty(string $property, bool $merge = false) |
| 202 | 208 | { |
| 203 | - if (isset($this->propertyCache[$property])) { |
|
| 209 | + if (isset($this->propertyCache[$property])) |
|
| 210 | + { |
|
| 204 | 211 | //Property merging and trait events are pretty slow |
| 205 | 212 | return $this->propertyCache[$property]; |
| 206 | 213 | } |
@@ -208,27 +215,35 @@ discard block |
||
| 208 | 215 | $properties = $this->reflection->getDefaultProperties(); |
| 209 | 216 | $constants = $this->reflection->getConstants(); |
| 210 | 217 | |
| 211 | - if (isset($properties[$property])) { |
|
| 218 | + if (isset($properties[$property])) |
|
| 219 | + { |
|
| 212 | 220 | //Read from default value |
| 213 | 221 | $value = $properties[$property]; |
| 214 | - } elseif (isset($constants[strtoupper($property)])) { |
|
| 222 | + } |
|
| 223 | + elseif (isset($constants[strtoupper($property)])) |
|
| 224 | + { |
|
| 215 | 225 | //Read from a constant |
| 216 | 226 | $value = $constants[strtoupper($property)]; |
| 217 | - } else { |
|
| 227 | + } |
|
| 228 | + else |
|
| 229 | + { |
|
| 218 | 230 | return null; |
| 219 | 231 | } |
| 220 | 232 | |
| 221 | 233 | //Merge with parent value requested |
| 222 | - if ($merge && is_array($value) && !empty($parent = $this->parentReflection())) { |
|
| 234 | + if ($merge && is_array($value) && !empty($parent = $this->parentReflection())) |
|
| 235 | + { |
|
| 223 | 236 | $parentValue = $parent->getProperty($property, $merge); |
| 224 | 237 | |
| 225 | - if (is_array($parentValue)) { |
|
| 238 | + if (is_array($parentValue)) |
|
| 239 | + { |
|
| 226 | 240 | //Class values prior to parent values |
| 227 | 241 | $value = array_merge($parentValue, $value); |
| 228 | 242 | } |
| 229 | 243 | } |
| 230 | 244 | |
| 231 | - if (!$this->reflection->isSubclassOf(SchematicEntity::class)) { |
|
| 245 | + if (!$this->reflection->isSubclassOf(SchematicEntity::class)) |
|
| 246 | + { |
|
| 232 | 247 | return $value; |
| 233 | 248 | } |
| 234 | 249 | |
@@ -245,7 +260,8 @@ discard block |
||
| 245 | 260 | { |
| 246 | 261 | $parentClass = $this->reflection->getParentClass(); |
| 247 | 262 | |
| 248 | - if (!empty($parentClass) && $parentClass->getName() != static::BASE_CLASS) { |
|
| 263 | + if (!empty($parentClass) && $parentClass->getName() != static::BASE_CLASS) |
|
| 264 | + { |
|
| 249 | 265 | $parent = clone $this; |
| 250 | 266 | $parent->reflection = $this->getParentClass(); |
| 251 | 267 | |
@@ -72,15 +72,15 @@ discard block |
||
| 72 | 72 | */ |
| 73 | 73 | protected function isFillable(string $field): bool |
| 74 | 74 | { |
| 75 | - if (static::FILLABLE === '*') { |
|
| 75 | + if (static::FILLABLE === '*'){ |
|
| 76 | 76 | return true; |
| 77 | 77 | } |
| 78 | 78 | |
| 79 | - if (!empty(static::FILLABLE)) { |
|
| 79 | + if (!empty(static::FILLABLE)){ |
|
| 80 | 80 | return in_array($field, static::FILLABLE); |
| 81 | 81 | } |
| 82 | 82 | |
| 83 | - if (static::SECURED === '*') { |
|
| 83 | + if (static::SECURED === '*'){ |
|
| 84 | 84 | return false; |
| 85 | 85 | } |
| 86 | 86 | |
@@ -99,7 +99,7 @@ discard block |
||
| 99 | 99 | protected function getMutator(string $field, string $mutator) |
| 100 | 100 | { |
| 101 | 101 | $target = []; |
| 102 | - switch ($mutator) { |
|
| 102 | + switch ($mutator){ |
|
| 103 | 103 | case ModelSchema::MUTATOR_ACCESSOR: |
| 104 | 104 | $target = static::ACCESSORS; |
| 105 | 105 | break; |
@@ -111,7 +111,7 @@ discard block |
||
| 111 | 111 | break; |
| 112 | 112 | } |
| 113 | 113 | |
| 114 | - if (isset($target[$field])) { |
|
| 114 | + if (isset($target[$field])){ |
|
| 115 | 115 | return $target[$field]; |
| 116 | 116 | } |
| 117 | 117 | |
@@ -72,15 +72,18 @@ discard block |
||
| 72 | 72 | */ |
| 73 | 73 | protected function isFillable(string $field): bool |
| 74 | 74 | { |
| 75 | - if (static::FILLABLE === '*') { |
|
| 75 | + if (static::FILLABLE === '*') |
|
| 76 | + { |
|
| 76 | 77 | return true; |
| 77 | 78 | } |
| 78 | 79 | |
| 79 | - if (!empty(static::FILLABLE)) { |
|
| 80 | + if (!empty(static::FILLABLE)) |
|
| 81 | + { |
|
| 80 | 82 | return in_array($field, static::FILLABLE); |
| 81 | 83 | } |
| 82 | 84 | |
| 83 | - if (static::SECURED === '*') { |
|
| 85 | + if (static::SECURED === '*') |
|
| 86 | + { |
|
| 84 | 87 | return false; |
| 85 | 88 | } |
| 86 | 89 | |
@@ -99,7 +102,8 @@ discard block |
||
| 99 | 102 | protected function getMutator(string $field, string $mutator) |
| 100 | 103 | { |
| 101 | 104 | $target = []; |
| 102 | - switch ($mutator) { |
|
| 105 | + switch ($mutator) |
|
| 106 | + { |
|
| 103 | 107 | case ModelSchema::MUTATOR_ACCESSOR: |
| 104 | 108 | $target = static::ACCESSORS; |
| 105 | 109 | break; |
@@ -111,7 +115,8 @@ discard block |
||
| 111 | 115 | break; |
| 112 | 116 | } |
| 113 | 117 | |
| 114 | - if (isset($target[$field])) { |
|
| 118 | + if (isset($target[$field])) |
|
| 119 | + { |
|
| 115 | 120 | return $target[$field]; |
| 116 | 121 | } |
| 117 | 122 | |
@@ -34,15 +34,15 @@ discard block |
||
| 34 | 34 | */ |
| 35 | 35 | protected function isFillable(string $field): bool |
| 36 | 36 | { |
| 37 | - if (!empty($this->schema[ModelSchema::FILLABLE]) && $this->schema[ModelSchema::FILLABLE] === '*') { |
|
| 37 | + if (!empty($this->schema[ModelSchema::FILLABLE]) && $this->schema[ModelSchema::FILLABLE] === '*'){ |
|
| 38 | 38 | return true; |
| 39 | 39 | } |
| 40 | 40 | |
| 41 | - if (!empty($this->schema[ModelSchema::FILLABLE])) { |
|
| 41 | + if (!empty($this->schema[ModelSchema::FILLABLE])){ |
|
| 42 | 42 | return in_array($field, $this->schema[ModelSchema::FILLABLE]); |
| 43 | 43 | } |
| 44 | 44 | |
| 45 | - if (!empty($this->schema[ModelSchema::SECURED]) && $this->schema[ModelSchema::SECURED] === '*') { |
|
| 45 | + if (!empty($this->schema[ModelSchema::SECURED]) && $this->schema[ModelSchema::SECURED] === '*'){ |
|
| 46 | 46 | return false; |
| 47 | 47 | } |
| 48 | 48 | |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | */ |
| 55 | 55 | protected function getMutator(string $field, string $mutator) |
| 56 | 56 | { |
| 57 | - if (isset($this->schema[ModelSchema::MUTATORS][$mutator][$field])) { |
|
| 57 | + if (isset($this->schema[ModelSchema::MUTATORS][$mutator][$field])){ |
|
| 58 | 58 | return $this->schema[ModelSchema::MUTATORS][$mutator][$field]; |
| 59 | 59 | } |
| 60 | 60 | |
@@ -34,15 +34,18 @@ discard block |
||
| 34 | 34 | */ |
| 35 | 35 | protected function isFillable(string $field): bool |
| 36 | 36 | { |
| 37 | - if (!empty($this->schema[ModelSchema::FILLABLE]) && $this->schema[ModelSchema::FILLABLE] === '*') { |
|
| 37 | + if (!empty($this->schema[ModelSchema::FILLABLE]) && $this->schema[ModelSchema::FILLABLE] === '*') |
|
| 38 | + { |
|
| 38 | 39 | return true; |
| 39 | 40 | } |
| 40 | 41 | |
| 41 | - if (!empty($this->schema[ModelSchema::FILLABLE])) { |
|
| 42 | + if (!empty($this->schema[ModelSchema::FILLABLE])) |
|
| 43 | + { |
|
| 42 | 44 | return in_array($field, $this->schema[ModelSchema::FILLABLE]); |
| 43 | 45 | } |
| 44 | 46 | |
| 45 | - if (!empty($this->schema[ModelSchema::SECURED]) && $this->schema[ModelSchema::SECURED] === '*') { |
|
| 47 | + if (!empty($this->schema[ModelSchema::SECURED]) && $this->schema[ModelSchema::SECURED] === '*') |
|
| 48 | + { |
|
| 46 | 49 | return false; |
| 47 | 50 | } |
| 48 | 51 | |
@@ -54,7 +57,8 @@ discard block |
||
| 54 | 57 | */ |
| 55 | 58 | protected function getMutator(string $field, string $mutator) |
| 56 | 59 | { |
| 57 | - if (isset($this->schema[ModelSchema::MUTATORS][$mutator][$field])) { |
|
| 60 | + if (isset($this->schema[ModelSchema::MUTATORS][$mutator][$field])) |
|
| 61 | + { |
|
| 58 | 62 | return $this->schema[ModelSchema::MUTATORS][$mutator][$field]; |
| 59 | 63 | } |
| 60 | 64 | |
@@ -20,7 +20,7 @@ |
||
| 20 | 20 | |
| 21 | 21 | protected static function filter($v) |
| 22 | 22 | { |
| 23 | - if (is_array($v)) { |
|
| 23 | + if (is_array($v)){ |
|
| 24 | 24 | throw new RuntimeException("can't be array"); |
| 25 | 25 | } |
| 26 | 26 | |
@@ -20,7 +20,8 @@ |
||
| 20 | 20 | |
| 21 | 21 | protected static function filter($v) |
| 22 | 22 | { |
| 23 | - if (is_array($v)) { |
|
| 23 | + if (is_array($v)) |
|
| 24 | + { |
|
| 24 | 25 | throw new RuntimeException("can't be array"); |
| 25 | 26 | } |
| 26 | 27 | |
@@ -75,7 +75,7 @@ |
||
| 75 | 75 | $this->assertEquals([], $entity->getValue()); |
| 76 | 76 | |
| 77 | 77 | $entity['a'] = 90; |
| 78 | - foreach ($entity as $key => $value) { |
|
| 78 | + foreach ($entity as $key => $value){ |
|
| 79 | 79 | $this->assertSame('a', $key); |
| 80 | 80 | $this->assertSame(90, $value); |
| 81 | 81 | } |
@@ -75,7 +75,8 @@ |
||
| 75 | 75 | $this->assertEquals([], $entity->getValue()); |
| 76 | 76 | |
| 77 | 77 | $entity['a'] = 90; |
| 78 | - foreach ($entity as $key => $value) { |
|
| 78 | + foreach ($entity as $key => $value) |
|
| 79 | + { |
|
| 79 | 80 | $this->assertSame('a', $key); |
| 80 | 81 | $this->assertSame(90, $value); |
| 81 | 82 | } |
@@ -20,7 +20,7 @@ |
||
| 20 | 20 | |
| 21 | 21 | protected function isNullable(string $field): bool |
| 22 | 22 | { |
| 23 | - if (parent::isNullable($field)) { |
|
| 23 | + if (parent::isNullable($field)){ |
|
| 24 | 24 | return true; |
| 25 | 25 | } |
| 26 | 26 | |
@@ -20,7 +20,8 @@ |
||
| 20 | 20 | |
| 21 | 21 | protected function isNullable(string $field): bool |
| 22 | 22 | { |
| 23 | - if (parent::isNullable($field)) { |
|
| 23 | + if (parent::isNullable($field)) |
|
| 24 | + { |
|
| 24 | 25 | return true; |
| 25 | 26 | } |
| 26 | 27 | |