@@ -13,11 +13,11 @@ discard block |
||
| 13 | 13 | { |
| 14 | 14 | public function getClassFromClassProperty($class, $property) |
| 15 | 15 | { |
| 16 | - if(!class_exists($class)) { |
|
| 17 | - throw new \Exception($class. ' not found or does not exist'); |
|
| 16 | + if (!class_exists($class)) { |
|
| 17 | + throw new \Exception($class . ' not found or does not exist'); |
|
| 18 | 18 | } |
| 19 | 19 | |
| 20 | - if(!property_exists($class, $property)) { |
|
| 20 | + if (!property_exists($class, $property)) { |
|
| 21 | 21 | throw new \Exception($class . ' has no property with the name ' . $property); |
| 22 | 22 | } |
| 23 | 23 | } |
@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | if (preg_match('~\@var[\s]+([A-Za-z0-9\\\\]+)~', $comment, $matches)) { |
| 37 | 37 | if ($includeNamespaces) { |
| 38 | 38 | if ($reflectionClass instanceof \ReflectionClass && !in_array($matches[1], HydratableTrait::$nonObjectTypes)) { |
| 39 | - if($reflectionClass->getNamespaceName()) { |
|
| 39 | + if ($reflectionClass->getNamespaceName()) { |
|
| 40 | 40 | return sprintf('\%s\%s', $reflectionClass->getNamespaceName(), $matches[1]); |
| 41 | 41 | } else { |
| 42 | 42 | return sprintf('\%s', $matches[1]); |
@@ -11,8 +11,7 @@ discard block |
||
| 11 | 11 | */ |
| 12 | 12 | trait ReflectionTrait |
| 13 | 13 | { |
| 14 | - public function getClassFromClassProperty($class, $property) |
|
| 15 | - { |
|
| 14 | + public function getClassFromClassProperty($class, $property) { |
|
| 16 | 15 | if(!class_exists($class)) { |
| 17 | 16 | throw new \Exception($class. ' not found or does not exist'); |
| 18 | 17 | } |
@@ -31,8 +30,7 @@ discard block |
||
| 31 | 30 | * |
| 32 | 31 | * @return bool|string |
| 33 | 32 | */ |
| 34 | - public static function getClassFromDocComment($comment, $includeNamespaces = true, $reflectionClass = null) |
|
| 35 | - { |
|
| 33 | + public static function getClassFromDocComment($comment, $includeNamespaces = true, $reflectionClass = null) { |
|
| 36 | 34 | if (preg_match('~\@var[\s]+([A-Za-z0-9\\\\]+)~', $comment, $matches)) { |
| 37 | 35 | if ($includeNamespaces) { |
| 38 | 36 | if ($reflectionClass instanceof \ReflectionClass && !in_array($matches[1], HydratableTrait::$nonObjectTypes)) { |
@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | * |
| 32 | 32 | * @return bool|string |
| 33 | 33 | */ |
| 34 | - public static function getClassFromDocComment($comment, $includeNamespaces = true, $reflectionClass = null) |
|
| 34 | + public static function getClassFromDocComment($comment, $includeNamespaces = TRUE, $reflectionClass = NULL) |
|
| 35 | 35 | { |
| 36 | 36 | if (preg_match('~\@var[\s]+([A-Za-z0-9\\\\]+)~', $comment, $matches)) { |
| 37 | 37 | if ($includeNamespaces) { |
@@ -49,6 +49,6 @@ discard block |
||
| 49 | 49 | } |
| 50 | 50 | } |
| 51 | 51 | |
| 52 | - return false; |
|
| 52 | + return FALSE; |
|
| 53 | 53 | } |
| 54 | 54 | } |
| 55 | 55 | \ No newline at end of file |
@@ -64,9 +64,7 @@ discard block |
||
| 64 | 64 | |
| 65 | 65 | // Convert key to a propertyname in $this |
| 66 | 66 | $propertyName = lcfirst(str_replace(' ', '', ucwords(str_replace('_', ' ', $itemKey)))); |
| 67 | - $propertyName = (property_exists($this, $propertyName)) ? $propertyName : |
|
| 68 | - (property_exists($this, lcfirst($propertyName)) ? lcfirst($propertyName) : |
|
| 69 | - preg_replace_callback('/([A-Z])/', function ($match) { |
|
| 67 | + $propertyName = (property_exists($this, $propertyName)) ? $propertyName : (property_exists($this, lcfirst($propertyName)) ? lcfirst($propertyName) : preg_replace_callback('/([A-Z])/', function ($match) { |
|
| 70 | 68 | return strtolower('_' . $match[1]); |
| 71 | 69 | }, lcfirst($propertyName)) |
| 72 | 70 | ); |
@@ -87,7 +85,7 @@ discard block |
||
| 87 | 85 | |
| 88 | 86 | if (in_array($propertyClassName, self::$nonObjectTypes)) { |
| 89 | 87 | $this->setPropertyValue($propertyName, $itemValue, true); |
| 90 | - } elseif(interface_exists($propertyClassName)) { |
|
| 88 | + } elseif (interface_exists($propertyClassName)) { |
|
| 91 | 89 | // We cannot instantiate an interface, so we skip it |
| 92 | 90 | continue; |
| 93 | 91 | } else { |
@@ -54,8 +54,7 @@ discard block |
||
| 54 | 54 | * @param object|array $class class |
| 55 | 55 | * @return object |
| 56 | 56 | */ |
| 57 | - public function hydrateClass($class) |
|
| 58 | - { |
|
| 57 | + public function hydrateClass($class) { |
|
| 59 | 58 | $reflection = new \ReflectionClass($this); |
| 60 | 59 | |
| 61 | 60 | // Iterate over $class for properties |
@@ -123,8 +122,7 @@ discard block |
||
| 123 | 122 | * @param bool $fix Fix errors |
| 124 | 123 | * @return void |
| 125 | 124 | */ |
| 126 | - private function checkObjectForErrors(&$object, $fix = false) |
|
| 127 | - { |
|
| 125 | + private function checkObjectForErrors(&$object, $fix = false) { |
|
| 128 | 126 | if ($object instanceof \DateTime) { |
| 129 | 127 | // The constructor (passed from the API) is NULL, indicating an empty value |
| 130 | 128 | // PHP DateTime's default value is now() |
@@ -77,16 +77,16 @@ discard block |
||
| 77 | 77 | && $reflectionProperty = $reflection->getProperty($propertyName) |
| 78 | 78 | ) { |
| 79 | 79 | // Get the expected property class from the property's DocBlock |
| 80 | - if ($propertyClassName = ReflectionTrait::getClassFromDocComment($reflectionProperty->getDocComment(), true, |
|
| 80 | + if ($propertyClassName = ReflectionTrait::getClassFromDocComment($reflectionProperty->getDocComment(), TRUE, |
|
| 81 | 81 | $reflection) |
| 82 | 82 | ) { |
| 83 | 83 | |
| 84 | 84 | // Set argument for constructor (if any), in case we're dealing with an object (IE: DateTime) |
| 85 | 85 | $this->objectConstructorArguments = (in_array($propertyClassName, $this->giveDataInConstructor)) |
| 86 | - ? $itemValue : null; |
|
| 86 | + ? $itemValue : NULL; |
|
| 87 | 87 | |
| 88 | 88 | if (in_array($propertyClassName, self::$nonObjectTypes)) { |
| 89 | - $this->setPropertyValue($propertyName, $itemValue, true); |
|
| 89 | + $this->setPropertyValue($propertyName, $itemValue, TRUE); |
|
| 90 | 90 | } elseif(interface_exists($propertyClassName)) { |
| 91 | 91 | // We cannot instantiate an interface, so we skip it |
| 92 | 92 | continue; |
@@ -95,7 +95,7 @@ discard block |
||
| 95 | 95 | |
| 96 | 96 | // Check if $object has valid values |
| 97 | 97 | // IE: DateTime with a negative timestamp will cause a SQL Error |
| 98 | - $this->checkObjectForErrors($object, true); |
|
| 98 | + $this->checkObjectForErrors($object, TRUE); |
|
| 99 | 99 | |
| 100 | 100 | if ($object) { |
| 101 | 101 | if ( |
@@ -105,7 +105,7 @@ discard block |
||
| 105 | 105 | $object->fromClass($itemValue); |
| 106 | 106 | } |
| 107 | 107 | // We're done. Assign the result to the propery of $this |
| 108 | - $this->setPropertyValue($propertyName, $object, true); |
|
| 108 | + $this->setPropertyValue($propertyName, $object, TRUE); |
|
| 109 | 109 | } |
| 110 | 110 | } |
| 111 | 111 | unset($object); |
@@ -123,13 +123,13 @@ discard block |
||
| 123 | 123 | * @param bool $fix Fix errors |
| 124 | 124 | * @return void |
| 125 | 125 | */ |
| 126 | - private function checkObjectForErrors(&$object, $fix = false) |
|
| 126 | + private function checkObjectForErrors(&$object, $fix = FALSE) |
|
| 127 | 127 | { |
| 128 | 128 | if ($object instanceof \DateTime) { |
| 129 | 129 | // The constructor (passed from the API) is NULL, indicating an empty value |
| 130 | 130 | // PHP DateTime's default value is now() |
| 131 | - if ($this->objectConstructorArguments == null) { |
|
| 132 | - $object = null; |
|
| 131 | + if ($this->objectConstructorArguments == NULL) { |
|
| 132 | + $object = NULL; |
|
| 133 | 133 | } else { |
| 134 | 134 | if (!$object->getTimestamp()) { |
| 135 | 135 | // DateTime has a negative or false value |