@@ -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,12 +48,12 @@ 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 | - public static function fromArray( array $properties, $discardInvalidEntries = false ) |
|
51 | + public static function fromArray(array $properties, $discardInvalidEntries = false) |
|
52 | 52 | { |
53 | 53 | $selfClass = get_called_class(); |
54 | 54 | $obj = new $selfClass(); |
55 | - foreach( $properties as $property=>$value ){ |
|
56 | - if( (! property_exists( get_called_class(), $property ) ) && $discardInvalidEntries ){ |
|
55 | + foreach ($properties as $property=>$value) { |
|
56 | + if (( ! property_exists(get_called_class(), $property)) && $discardInvalidEntries) { |
|
57 | 57 | continue; |
58 | 58 | } |
59 | 59 | $obj->$property = $value; |
@@ -91,9 +91,9 @@ discard block |
||
91 | 91 | */ |
92 | 92 | public function validate() |
93 | 93 | { |
94 | - if( ! defined( "structclass-AnnotationRegistry-initilised" )){ |
|
95 | - define( "structclass-AnnotationRegistry-initilised", true ); |
|
96 | - AnnotationRegistry::registerLoader(function ($class) {return class_exists($class);}); |
|
94 | + if ( ! defined("structclass-AnnotationRegistry-initilised")) { |
|
95 | + define("structclass-AnnotationRegistry-initilised", true); |
|
96 | + AnnotationRegistry::registerLoader(function($class) {return class_exists($class); }); |
|
97 | 97 | } |
98 | 98 | $validator = Validation::createValidatorBuilder() |
99 | 99 | ->enableAnnotationMapping() |
@@ -101,32 +101,32 @@ discard block |
||
101 | 101 | |
102 | 102 | $violations = $validator->validate($this); |
103 | 103 | $errs = ''; |
104 | - if( $violations->count() > 0 ){ |
|
104 | + if ($violations->count() > 0) { |
|
105 | 105 | $errs = 'Invalid properties in '.get_called_class()."\n"; |
106 | 106 | /** @var \Symfony\Component\Validator\ConstraintViolationInterface $issue */ |
107 | - foreach( $violations as $issue ){ |
|
107 | + foreach ($violations as $issue) { |
|
108 | 108 | $errs .= |
109 | 109 | $issue->getPropertyPath() |
110 | 110 | ." : " |
111 | 111 | .$issue->getMessage() |
112 | 112 | . " But got " |
113 | - . var_export( $issue->getInvalidValue(), true ); |
|
113 | + . var_export($issue->getInvalidValue(), true); |
|
114 | 114 | } |
115 | 115 | } |
116 | 116 | // Validate any properties which are StructClasses or are arrays containing StructClasses |
117 | 117 | foreach ($this as $property) { |
118 | 118 | if ($property instanceof StructClass) { |
119 | - try{ |
|
119 | + try { |
|
120 | 120 | $property->validate(); |
121 | - }catch( \Exception $e ){ |
|
121 | + }catch (\Exception $e) { |
|
122 | 122 | $errs .= $e->getMessage(); |
123 | 123 | } |
124 | - }elseif (is_array( $property )) { |
|
124 | + }elseif (is_array($property)) { |
|
125 | 125 | foreach ($property as $element) { |
126 | 126 | if ($element instanceof StructClass) { |
127 | - try{ |
|
127 | + try { |
|
128 | 128 | $element->validate(); |
129 | - }catch( \Exception $e ){ |
|
129 | + }catch (\Exception $e) { |
|
130 | 130 | $errs .= $e->getMessage(); |
131 | 131 | } |
132 | 132 | } |
@@ -134,7 +134,7 @@ discard block |
||
134 | 134 | } |
135 | 135 | } |
136 | 136 | if ($errs != '') { |
137 | - throw new \Exception( $errs ); |
|
137 | + throw new \Exception($errs); |
|
138 | 138 | } |
139 | 139 | } |
140 | 140 |