11<?php
2+
23/**
3- * Copyright (c) Saint Systems, LLC. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information.
4- *
5- * OData Entity File
6- * PHP version 7
7- *
8- * @category Library
9- * @package SaintSystems.OData
10- * @copyright 2017 Saint Systems, LLC
11- * @license https://opensource.org/licenses/MIT MIT License
12- * @version GIT: 0.1.0
13- */
4+ * Copyright (c) Saint Systems, LLC. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information.
5+ *
6+ * OData Entity File
7+ * PHP version 7
8+ *
9+ * @category Library
10+ * @package SaintSystems.OData
11+ * @copyright 2017 Saint Systems, LLC
12+ * @license https://opensource.org/licenses/MIT MIT License
13+ * @version GIT: 0.1.0
14+ */
15+
1416namespace SaintSystems \OData ;
1517
1618// use Closure;
2830use SaintSystems \OData \Exception \MassAssignmentException ;
2931
3032/**
31- * Entity class
32- *
33- * @package SaintSystems.OData
34- * @copyright 2017 Saint Systems, LLC
35- * @license https://opensource.org/licenses/MIT MIT License
36- * @version Release: 0.1.0
37- */
33+ * Entity class
34+ *
35+ * @package SaintSystems.OData
36+ * @copyright 2017 Saint Systems, LLC
37+ * @license https://opensource.org/licenses/MIT MIT License
38+ * @version Release: 0.1.0
39+ */
3840class Entity implements ArrayAccess, Arrayable
3941{
4042 /**
@@ -124,7 +126,7 @@ class Entity implements ArrayAccess, Arrayable
124126 *
125127 * @var array
126128 */
127- protected $ guarded = [];//['*'];
129+ protected $ guarded = []; //['*'];
128130
129131 /**
130132 * The properties that should be mutated to dates.
@@ -186,12 +188,12 @@ class Entity implements ArrayAccess, Arrayable
186188 private $ entity ;
187189
188190 /**
189- * Construct a new Entity
190- *
191- * @param array $properties A list of properties to set
192- *
193- * @return Entity
194- */
191+ * Construct a new Entity
192+ *
193+ * @param array $properties A list of properties to set
194+ *
195+ * @return Entity
196+ */
195197 function __construct ($ properties = array ())
196198 {
197199 $ this ->bootIfNotBooted ();
@@ -210,7 +212,7 @@ function __construct($properties = array())
210212 */
211213 protected function bootIfNotBooted ()
212214 {
213- if (! isset (static ::$ booted [static ::class])) {
215+ if (!isset (static ::$ booted [static ::class])) {
214216 static ::$ booted [static ::class] = true ;
215217
216218 // $this->fireModelEvent('booting', false);
@@ -241,7 +243,7 @@ protected static function bootTraits()
241243 $ class = static ::class;
242244
243245 foreach (class_uses_recursive ($ class ) as $ trait ) {
244- if (method_exists ($ class , $ method = 'boot ' . class_basename ($ trait ))) {
246+ if (method_exists ($ class , $ method = 'boot ' . class_basename ($ trait ))) {
245247 forward_static_call ([$ class , $ method ]);
246248 }
247249 }
@@ -307,7 +309,7 @@ public function forceFill(array $properties)
307309 */
308310 protected function fillableFromArray (array $ properties )
309311 {
310- if (count ($ this ->getFillable ()) > 0 && ! static ::$ unguarded ) {
312+ if (count ($ this ->getFillable ()) > 0 && !static ::$ unguarded ) {
311313 return array_intersect_key ($ properties , array_flip ($ this ->getFillable ()));
312314 }
313315
@@ -463,7 +465,7 @@ public function makeVisible($properties)
463465 {
464466 $ this ->hidden = array_diff ($ this ->hidden , (array ) $ properties );
465467
466- if (! empty ($ this ->visible )) {
468+ if (!empty ($ this ->visible )) {
467469 $ this ->addVisible ($ properties );
468470 }
469471
@@ -699,7 +701,7 @@ public function isFillable($key)
699701 return false ;
700702 }
701703
702- return empty ($ this ->getFillable ()) && ! Str::startsWith ($ key , '_ ' );
704+ return empty ($ this ->getFillable ()) && !Str::startsWith ($ key , '_ ' );
703705 }
704706
705707 /**
@@ -724,10 +726,10 @@ public function totallyGuarded()
724726 }
725727
726728 /**
727- * Gets the property dictionary of the Entity
728- *
729- * @return array The list of properties
730- */
729+ * Gets the property dictionary of the Entity
730+ *
731+ * @return array The list of properties
732+ */
731733 public function getProperties ()
732734 {
733735 return $ this ->properties ;
@@ -865,7 +867,7 @@ public function offsetUnset($offset): void
865867 */
866868 public function __isset ($ key )
867869 {
868- return ! is_null ($ this ->getProperty ($ key ));
870+ return !is_null ($ this ->getProperty ($ key ));
869871 }
870872
871873 /**
@@ -977,7 +979,7 @@ protected function castProperty($key, $value)
977979 case 'array ' :
978980 case 'json ' :
979981 return $ this ->fromJson ($ value );
980- //case 'collection':
982+ //case 'collection':
981983 //return new BaseCollection($this->fromJson($value));
982984 case 'date ' :
983985 return $ this ->asDate ($ value );
@@ -1004,7 +1006,7 @@ public function setProperty($key, $value)
10041006 // which simply lets the developers tweak the property as it is set on
10051007 // the entity, such as "json_encoding" a listing of data for storage.
10061008 if ($ this ->hasSetMutator ($ key )) {
1007- $ method = 'set ' . Str::studly ($ key ). 'Property ' ;
1009+ $ method = 'set ' . Str::studly ($ key ) . 'Property ' ;
10081010
10091011 return $ this ->{$ method }($ value );
10101012 }
@@ -1016,7 +1018,7 @@ public function setProperty($key, $value)
10161018 $ value = $ this ->fromDateTime ($ value );
10171019 }
10181020
1019- if ($ this ->isJsonCastable ($ key ) && ! is_null ($ value )) {
1021+ if ($ this ->isJsonCastable ($ key ) && !is_null ($ value )) {
10201022 $ value = $ this ->asJson ($ value );
10211023 }
10221024
@@ -1040,7 +1042,7 @@ public function setProperty($key, $value)
10401042 */
10411043 public function hasSetMutator ($ key )
10421044 {
1043- return method_exists ($ this , 'set ' . Str::studly ($ key ). 'Property ' );
1045+ return method_exists ($ this , 'set ' . Str::studly ($ key ) . 'Property ' );
10441046 }
10451047
10461048 /**
@@ -1086,7 +1088,8 @@ protected function asDateTime($value)
10861088 // when checking the field. We will just return the DateTime right away.
10871089 if ($ value instanceof DateTimeInterface) {
10881090 return Date::parse (
1089- $ value ->format ('Y-m-d H:i:s.u ' ), $ value ->getTimezone ()
1091+ $ value ->format ('Y-m-d H:i:s.u ' ),
1092+ $ value ->getTimezone ()
10901093 );
10911094 }
10921095 // If this value is an integer, we will assume it is a UNIX timestamp's value
@@ -1165,7 +1168,7 @@ protected function serializeDate(DateTimeInterface $date)
11651168 */
11661169 protected function getDateFormat ()
11671170 {
1168- return $ this ->dateFormat ;// ?: $this->getConnection()->getQueryGrammar()->getDateFormat();
1171+ return $ this ->dateFormat ; // ?: $this->getConnection()->getQueryGrammar()->getDateFormat();
11691172 }
11701173
11711174 /**
@@ -1201,7 +1204,7 @@ protected function asJson($value)
12011204 */
12021205 public function fromJson ($ value , $ asObject = false )
12031206 {
1204- return json_decode ($ value , ! $ asObject );
1207+ return json_decode ($ value , !$ asObject );
12051208 }
12061209
12071210 /**
@@ -1313,7 +1316,7 @@ public function propertiesToArray()
13131316 protected function addDatePropertiesToArray (array $ properties )
13141317 {
13151318 foreach ($ this ->getDates () as $ key ) {
1316- if (! isset ($ properties [$ key ])) {
1319+ if (!isset ($ properties [$ key ])) {
13171320 continue ;
13181321 }
13191322
@@ -1338,15 +1341,16 @@ protected function addMutatedPropertiesToArray(array $properties, array $mutated
13381341 // We want to spin through all the mutated properties for this model and call
13391342 // the mutator for the properties. We cache off every mutated properties so
13401343 // we don't have to constantly check on properties that actually change.
1341- if (! array_key_exists ($ key , $ properties )) {
1344+ if (!array_key_exists ($ key , $ properties )) {
13421345 continue ;
13431346 }
13441347
13451348 // Next, we will call the mutator for this properties so that we can get these
13461349 // mutated property's actual values. After we finish mutating each of the
13471350 // properties we will return this final array of the mutated properties.
13481351 $ properties [$ key ] = $ this ->mutatePropertyForArray (
1349- $ key , $ properties [$ key ]
1352+ $ key ,
1353+ $ properties [$ key ]
13501354 );
13511355 }
13521356
@@ -1363,22 +1367,25 @@ protected function addMutatedPropertiesToArray(array $properties, array $mutated
13631367 protected function addCastPropertiesToArray (array $ properties , array $ mutatedProperties )
13641368 {
13651369 foreach ($ this ->getCasts () as $ key => $ value ) {
1366- if (! array_key_exists ($ key , $ properties ) || in_array ($ key , $ mutatedProperties )) {
1370+ if (!array_key_exists ($ key , $ properties ) || in_array ($ key , $ mutatedProperties )) {
13671371 continue ;
13681372 }
13691373
13701374 // Here we will cast the property. Then, if the cast is a date or datetime cast
13711375 // then we will serialize the date for the array. This will convert the dates
13721376 // to strings based on the date format specified for these Entity models.
13731377 $ properties [$ key ] = $ this ->castProperty (
1374- $ key , $ properties [$ key ]
1378+ $ key ,
1379+ $ properties [$ key ]
13751380 );
13761381
13771382 // If the property cast was a date or a datetime, we will serialize the date as
13781383 // a string. This allows the developers to customize how dates are serialized
13791384 // into an array without affecting how they are persisted into the storage.
1380- if ($ properties [$ key ] &&
1381- ($ value === 'date ' || $ value === 'datetime ' )) {
1385+ if (
1386+ $ properties [$ key ] &&
1387+ ($ value === 'date ' || $ value === 'datetime ' )
1388+ ) {
13821389 $ properties [$ key ] = $ this ->serializeDate ($ properties [$ key ]);
13831390 }
13841391 }
@@ -1403,7 +1410,7 @@ protected function getArrayableProperties()
14031410 */
14041411 protected function getArrayableAppends ()
14051412 {
1406- if (! count ($ this ->appends )) {
1413+ if (!count ($ this ->appends )) {
14071414 return [];
14081415 }
14091416
@@ -1493,7 +1500,7 @@ protected function getArrayableItems(array $values)
14931500 */
14941501 public function getProperty ($ key )
14951502 {
1496- if (! $ key ) {
1503+ if (!$ key ) {
14971504 return ;
14981505 }
14991506
@@ -1504,8 +1511,10 @@ public function getProperty($key)
15041511 // If the property exists in the properties array or has a "get" mutator we will
15051512 // get the property's value. Otherwise, we will proceed as if the developers
15061513 // are asking for a relationship's value. This covers both types of values.
1507- if (array_key_exists ($ key , $ this ->properties ) ||
1508- $ this ->hasGetMutator ($ key )) {
1514+ if (
1515+ array_key_exists ($ key , $ this ->properties ) ||
1516+ $ this ->hasGetMutator ($ key )
1517+ ) {
15091518 return $ this ->getPropertyValue ($ key );
15101519 }
15111520
@@ -1547,8 +1556,10 @@ public function getPropertyValue($key)
15471556 // If the property is listed as a date, we will convert it to a DateTime
15481557 // instance on retrieval, which makes it quite convenient to work with
15491558 // date fields without having to create a mutator for each property.
1550- if (in_array ($ key , $ this ->getDates ()) &&
1551- ! is_null ($ value )) {
1559+ if (
1560+ in_array ($ key , $ this ->getDates ()) &&
1561+ !is_null ($ value )
1562+ ) {
15521563 return $ this ->asDateTime ($ value );
15531564 }
15541565
@@ -1576,7 +1587,7 @@ protected function getPropertyFromArray($key)
15761587 */
15771588 public function hasGetMutator ($ key )
15781589 {
1579- return method_exists ($ this , 'get ' . Str::studly ($ key ). 'Property ' );
1590+ return method_exists ($ this , 'get ' . Str::studly ($ key ) . 'Property ' );
15801591 //return method_exists($this, 'get_'.$key);
15811592 }
15821593
@@ -1589,7 +1600,7 @@ public function hasGetMutator($key)
15891600 */
15901601 protected function mutateProperty ($ key , $ value )
15911602 {
1592- return $ this ->{'get ' . Str::studly ($ key ). 'Property ' }($ value );
1603+ return $ this ->{'get ' . Str::studly ($ key ) . 'Property ' }($ value );
15931604 // return $this->{'get_'.$key}($value);
15941605 }
15951606
0 commit comments