@@ -26,9 +26,9 @@ discard block |
||
| 26 | 26 | * @param $property |
| 27 | 27 | * @throws \Exception |
| 28 | 28 | */ |
| 29 | - public function __get( $property ) |
|
| 29 | + public function __get($property) |
|
| 30 | 30 | { |
| 31 | - throw new \Exception( "Non-existent property {$property} get in " . get_class( $this ) ); |
|
| 31 | + throw new \Exception("Non-existent property {$property} get in ".get_class($this)); |
|
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | /** |
@@ -37,9 +37,9 @@ discard block |
||
| 37 | 37 | * @param $value |
| 38 | 38 | * @throws \Exception |
| 39 | 39 | */ |
| 40 | - public function __set( $property, $value ) |
|
| 40 | + public function __set($property, $value) |
|
| 41 | 41 | { |
| 42 | - throw new \Exception( "Non-existent property {$property} set in " . get_class( $this ) ); |
|
| 42 | + throw new \Exception("Non-existent property {$property} set in ".get_class($this)); |
|
| 43 | 43 | } |
| 44 | 44 | |
| 45 | 45 | /** |
@@ -48,11 +48,11 @@ discard block |
||
| 48 | 48 | * @param bool $discardInvalidEntries If set to true, entries in $properties for which there is no corresponding class member will be discarded instead of generating an error |
| 49 | 49 | * @return StructClass |
| 50 | 50 | */ |
| 51 | - static function fromArray( array $properties, $discardInvalidEntries=false ){ |
|
| 51 | + static function fromArray(array $properties, $discardInvalidEntries = false) { |
|
| 52 | 52 | $selfClass = get_called_class(); |
| 53 | 53 | $obj = new $selfClass(); |
| 54 | - foreach( $properties as $property=>$value ){ |
|
| 55 | - if( (! property_exists( get_called_class(), $property ) ) && $discardInvalidEntries ){ |
|
| 54 | + foreach ($properties as $property=>$value) { |
|
| 55 | + if (( ! property_exists(get_called_class(), $property)) && $discardInvalidEntries) { |
|
| 56 | 56 | continue; |
| 57 | 57 | } |
| 58 | 58 | $obj->$property = $value; |
@@ -88,10 +88,10 @@ discard block |
||
| 88 | 88 | * Validate class using annotations |
| 89 | 89 | * @throws \Exception |
| 90 | 90 | */ |
| 91 | - function validate(){ |
|
| 92 | - if( ! defined( "structclass-AnnotationRegistry-initilised" )){ |
|
| 93 | - define( "structclass-AnnotationRegistry-initilised", true ); |
|
| 94 | - AnnotationRegistry::registerLoader(function ($class) {return class_exists($class);}); |
|
| 91 | + function validate() { |
|
| 92 | + if ( ! defined("structclass-AnnotationRegistry-initilised")) { |
|
| 93 | + define("structclass-AnnotationRegistry-initilised", true); |
|
| 94 | + AnnotationRegistry::registerLoader(function($class) {return class_exists($class); }); |
|
| 95 | 95 | } |
| 96 | 96 | $validator = Validation::createValidatorBuilder() |
| 97 | 97 | ->enableAnnotationMapping() |
@@ -99,33 +99,33 @@ discard block |
||
| 99 | 99 | |
| 100 | 100 | $violations = $validator->validate($this); |
| 101 | 101 | $errs = ''; |
| 102 | - if( $violations->count() > 0 ){ |
|
| 102 | + if ($violations->count() > 0) { |
|
| 103 | 103 | $errs = 'Invalid properties in '.get_called_class()."\n"; |
| 104 | 104 | /** @var \Symfony\Component\Validator\ConstraintViolationInterface $issue */ |
| 105 | - foreach( $violations as $issue ){ |
|
| 105 | + foreach ($violations as $issue) { |
|
| 106 | 106 | $errs .= |
| 107 | 107 | $issue->getPropertyPath() |
| 108 | 108 | ." : " |
| 109 | 109 | .$issue->getMessage() |
| 110 | 110 | . " But got " |
| 111 | - . var_export( $issue->getInvalidValue(), true ); |
|
| 111 | + . var_export($issue->getInvalidValue(), true); |
|
| 112 | 112 | //. " (" . gettype( $issue->getInvalidValue() ) . ").\n"; |
| 113 | 113 | } |
| 114 | 114 | } |
| 115 | 115 | // Validate any properties which are StructClasses or are arrays containing StructClasses |
| 116 | 116 | foreach ($this as $property) { |
| 117 | 117 | if ($property instanceof StructClass) { |
| 118 | - try{ |
|
| 118 | + try { |
|
| 119 | 119 | $property->validate(); |
| 120 | - }catch( \Exception $e ){ |
|
| 120 | + }catch (\Exception $e) { |
|
| 121 | 121 | $errs .= $e->getMessage(); |
| 122 | 122 | } |
| 123 | - }elseif (is_array( $property )) { |
|
| 123 | + }elseif (is_array($property)) { |
|
| 124 | 124 | foreach ($property as $element) { |
| 125 | 125 | if ($element instanceof StructClass) { |
| 126 | - try{ |
|
| 126 | + try { |
|
| 127 | 127 | $element->validate(); |
| 128 | - }catch( \Exception $e ){ |
|
| 128 | + }catch (\Exception $e) { |
|
| 129 | 129 | $errs .= $e->getMessage(); |
| 130 | 130 | } |
| 131 | 131 | } |
@@ -133,7 +133,7 @@ discard block |
||
| 133 | 133 | } |
| 134 | 134 | } |
| 135 | 135 | if ($errs != '') { |
| 136 | - throw new \Exception( $errs ); |
|
| 136 | + throw new \Exception($errs); |
|
| 137 | 137 | } |
| 138 | 138 | } |
| 139 | 139 | |
@@ -117,15 +117,15 @@ |
||
| 117 | 117 | if ($property instanceof StructClass) { |
| 118 | 118 | try{ |
| 119 | 119 | $property->validate(); |
| 120 | - }catch( \Exception $e ){ |
|
| 120 | + } catch( \Exception $e ){ |
|
| 121 | 121 | $errs .= $e->getMessage(); |
| 122 | 122 | } |
| 123 | - }elseif (is_array( $property )) { |
|
| 123 | + } elseif (is_array( $property )) { |
|
| 124 | 124 | foreach ($property as $element) { |
| 125 | 125 | if ($element instanceof StructClass) { |
| 126 | 126 | try{ |
| 127 | 127 | $element->validate(); |
| 128 | - }catch( \Exception $e ){ |
|
| 128 | + } catch( \Exception $e ){ |
|
| 129 | 129 | $errs .= $e->getMessage(); |
| 130 | 130 | } |
| 131 | 131 | } |