Completed
Push — develop ( 316159...00443b )
by Zack
20:22
created
vendor/justinrainbow/json-schema/src/JsonSchema/Constraints/Constraint.php 1 patch
Spacing   +50 added lines, -50 removed lines patch added patch discarded remove patch
@@ -21,15 +21,15 @@  discard block
 block discarded – undo
21 21
 {
22 22
     protected $inlineSchemaProperty = '$schema';
23 23
 
24
-    const CHECK_MODE_NONE =             0x00000000;
25
-    const CHECK_MODE_NORMAL =           0x00000001;
26
-    const CHECK_MODE_TYPE_CAST =        0x00000002;
27
-    const CHECK_MODE_COERCE_TYPES =     0x00000004;
28
-    const CHECK_MODE_APPLY_DEFAULTS =   0x00000008;
29
-    const CHECK_MODE_EXCEPTIONS =       0x00000010;
30
-    const CHECK_MODE_DISABLE_FORMAT =   0x00000020;
31
-    const CHECK_MODE_ONLY_REQUIRED_DEFAULTS   = 0x00000080;
32
-    const CHECK_MODE_VALIDATE_SCHEMA =  0x00000100;
24
+    const CHECK_MODE_NONE = 0x00000000;
25
+    const CHECK_MODE_NORMAL = 0x00000001;
26
+    const CHECK_MODE_TYPE_CAST = 0x00000002;
27
+    const CHECK_MODE_COERCE_TYPES = 0x00000004;
28
+    const CHECK_MODE_APPLY_DEFAULTS = 0x00000008;
29
+    const CHECK_MODE_EXCEPTIONS = 0x00000010;
30
+    const CHECK_MODE_DISABLE_FORMAT = 0x00000020;
31
+    const CHECK_MODE_ONLY_REQUIRED_DEFAULTS = 0x00000080;
32
+    const CHECK_MODE_VALIDATE_SCHEMA = 0x00000100;
33 33
 
34 34
     /**
35 35
      * Bubble down the path
@@ -39,18 +39,18 @@  discard block
 block discarded – undo
39 39
      *
40 40
      * @return JsonPointer;
41 41
      */
42
-    protected function incrementPath(JsonPointer $path = null, $i)
42
+    protected function incrementPath( JsonPointer $path = null, $i )
43 43
     {
44
-        $path = $path ?: new JsonPointer('');
44
+        $path = $path ?: new JsonPointer( '' );
45 45
 
46
-        if ($i === null || $i === '') {
46
+        if ( $i === null || $i === '' ) {
47 47
             return $path;
48 48
         }
49 49
 
50 50
         $path = $path->withPropertyPaths(
51 51
             array_merge(
52 52
                 $path->getPropertyPaths(),
53
-                array($i)
53
+                array( $i )
54 54
             )
55 55
         );
56 56
 
@@ -65,12 +65,12 @@  discard block
 block discarded – undo
65 65
      * @param JsonPointer|null $path
66 66
      * @param mixed            $i
67 67
      */
68
-    protected function checkArray(&$value, $schema = null, JsonPointer $path = null, $i = null)
68
+    protected function checkArray( &$value, $schema = null, JsonPointer $path = null, $i = null )
69 69
     {
70
-        $validator = $this->factory->createInstanceFor('collection');
71
-        $validator->check($value, $schema, $path, $i);
70
+        $validator = $this->factory->createInstanceFor( 'collection' );
71
+        $validator->check( $value, $schema, $path, $i );
72 72
 
73
-        $this->addErrors($validator->getErrors());
73
+        $this->addErrors( $validator->getErrors() );
74 74
     }
75 75
 
76 76
     /**
@@ -83,13 +83,13 @@  discard block
 block discarded – undo
83 83
      * @param mixed            $additionalProperties
84 84
      * @param mixed            $patternProperties
85 85
      */
86
-    protected function checkObject(&$value, $schema = null, JsonPointer $path = null, $properties = null,
87
-        $additionalProperties = null, $patternProperties = null, $appliedDefaults = array())
86
+    protected function checkObject( &$value, $schema = null, JsonPointer $path = null, $properties = null,
87
+        $additionalProperties = null, $patternProperties = null, $appliedDefaults = array() )
88 88
     {
89
-        $validator = $this->factory->createInstanceFor('object');
90
-        $validator->check($value, $schema, $path, $properties, $additionalProperties, $patternProperties, $appliedDefaults);
89
+        $validator = $this->factory->createInstanceFor( 'object' );
90
+        $validator->check( $value, $schema, $path, $properties, $additionalProperties, $patternProperties, $appliedDefaults );
91 91
 
92
-        $this->addErrors($validator->getErrors());
92
+        $this->addErrors( $validator->getErrors() );
93 93
     }
94 94
 
95 95
     /**
@@ -100,12 +100,12 @@  discard block
 block discarded – undo
100 100
      * @param JsonPointer|null $path
101 101
      * @param mixed            $i
102 102
      */
103
-    protected function checkType(&$value, $schema = null, JsonPointer $path = null, $i = null)
103
+    protected function checkType( &$value, $schema = null, JsonPointer $path = null, $i = null )
104 104
     {
105
-        $validator = $this->factory->createInstanceFor('type');
106
-        $validator->check($value, $schema, $path, $i);
105
+        $validator = $this->factory->createInstanceFor( 'type' );
106
+        $validator->check( $value, $schema, $path, $i );
107 107
 
108
-        $this->addErrors($validator->getErrors());
108
+        $this->addErrors( $validator->getErrors() );
109 109
     }
110 110
 
111 111
     /**
@@ -116,13 +116,13 @@  discard block
 block discarded – undo
116 116
      * @param JsonPointer|null $path
117 117
      * @param mixed            $i
118 118
      */
119
-    protected function checkUndefined(&$value, $schema = null, JsonPointer $path = null, $i = null, $fromDefault = false)
119
+    protected function checkUndefined( &$value, $schema = null, JsonPointer $path = null, $i = null, $fromDefault = false )
120 120
     {
121
-        $validator = $this->factory->createInstanceFor('undefined');
121
+        $validator = $this->factory->createInstanceFor( 'undefined' );
122 122
 
123
-        $validator->check($value, $this->factory->getSchemaStorage()->resolveRefSchema($schema), $path, $i, $fromDefault);
123
+        $validator->check( $value, $this->factory->getSchemaStorage()->resolveRefSchema( $schema ), $path, $i, $fromDefault );
124 124
 
125
-        $this->addErrors($validator->getErrors());
125
+        $this->addErrors( $validator->getErrors() );
126 126
     }
127 127
 
128 128
     /**
@@ -133,12 +133,12 @@  discard block
 block discarded – undo
133 133
      * @param JsonPointer|null $path
134 134
      * @param mixed            $i
135 135
      */
136
-    protected function checkString($value, $schema = null, JsonPointer $path = null, $i = null)
136
+    protected function checkString( $value, $schema = null, JsonPointer $path = null, $i = null )
137 137
     {
138
-        $validator = $this->factory->createInstanceFor('string');
139
-        $validator->check($value, $schema, $path, $i);
138
+        $validator = $this->factory->createInstanceFor( 'string' );
139
+        $validator->check( $value, $schema, $path, $i );
140 140
 
141
-        $this->addErrors($validator->getErrors());
141
+        $this->addErrors( $validator->getErrors() );
142 142
     }
143 143
 
144 144
     /**
@@ -149,12 +149,12 @@  discard block
 block discarded – undo
149 149
      * @param JsonPointer $path
150 150
      * @param mixed       $i
151 151
      */
152
-    protected function checkNumber($value, $schema = null, JsonPointer $path = null, $i = null)
152
+    protected function checkNumber( $value, $schema = null, JsonPointer $path = null, $i = null )
153 153
     {
154
-        $validator = $this->factory->createInstanceFor('number');
155
-        $validator->check($value, $schema, $path, $i);
154
+        $validator = $this->factory->createInstanceFor( 'number' );
155
+        $validator->check( $value, $schema, $path, $i );
156 156
 
157
-        $this->addErrors($validator->getErrors());
157
+        $this->addErrors( $validator->getErrors() );
158 158
     }
159 159
 
160 160
     /**
@@ -165,12 +165,12 @@  discard block
 block discarded – undo
165 165
      * @param JsonPointer|null $path
166 166
      * @param mixed            $i
167 167
      */
168
-    protected function checkEnum($value, $schema = null, JsonPointer $path = null, $i = null)
168
+    protected function checkEnum( $value, $schema = null, JsonPointer $path = null, $i = null )
169 169
     {
170
-        $validator = $this->factory->createInstanceFor('enum');
171
-        $validator->check($value, $schema, $path, $i);
170
+        $validator = $this->factory->createInstanceFor( 'enum' );
171
+        $validator->check( $value, $schema, $path, $i );
172 172
 
173
-        $this->addErrors($validator->getErrors());
173
+        $this->addErrors( $validator->getErrors() );
174 174
     }
175 175
 
176 176
     /**
@@ -181,12 +181,12 @@  discard block
 block discarded – undo
181 181
      * @param JsonPointer|null $path
182 182
      * @param mixed            $i
183 183
      */
184
-    protected function checkFormat($value, $schema = null, JsonPointer $path = null, $i = null)
184
+    protected function checkFormat( $value, $schema = null, JsonPointer $path = null, $i = null )
185 185
     {
186
-        $validator = $this->factory->createInstanceFor('format');
187
-        $validator->check($value, $schema, $path, $i);
186
+        $validator = $this->factory->createInstanceFor( 'format' );
187
+        $validator->check( $value, $schema, $path, $i );
188 188
 
189
-        $this->addErrors($validator->getErrors());
189
+        $this->addErrors( $validator->getErrors() );
190 190
     }
191 191
 
192 192
     /**
@@ -204,15 +204,15 @@  discard block
 block discarded – undo
204 204
      *
205 205
      * @return string property path
206 206
      */
207
-    protected function convertJsonPointerIntoPropertyPath(JsonPointer $pointer)
207
+    protected function convertJsonPointerIntoPropertyPath( JsonPointer $pointer )
208 208
     {
209 209
         $result = array_map(
210
-            function ($path) {
211
-                return sprintf(is_numeric($path) ? '[%d]' : '.%s', $path);
210
+            function( $path ) {
211
+                return sprintf( is_numeric( $path ) ? '[%d]' : '.%s', $path );
212 212
             },
213 213
             $pointer->getPropertyPaths()
214 214
         );
215 215
 
216
-        return trim(implode('', $result), '.');
216
+        return trim( implode( '', $result ), '.' );
217 217
     }
218 218
 }
Please login to merge, or discard this patch.
justinrainbow/json-schema/src/JsonSchema/Constraints/EnumConstraint.php 1 patch
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -22,33 +22,33 @@
 block discarded – undo
22 22
     /**
23 23
      * {@inheritdoc}
24 24
      */
25
-    public function check(&$element, $schema = null, JsonPointer $path = null, $i = null)
25
+    public function check( &$element, $schema = null, JsonPointer $path = null, $i = null )
26 26
     {
27 27
         // Only validate enum if the attribute exists
28
-        if ($element instanceof UndefinedConstraint && (!isset($schema->required) || !$schema->required)) {
28
+        if ( $element instanceof UndefinedConstraint && ( ! isset( $schema->required ) || ! $schema->required ) ) {
29 29
             return;
30 30
         }
31
-        $type = gettype($element);
31
+        $type = gettype( $element );
32 32
 
33
-        foreach ($schema->enum as $enum) {
34
-            $enumType = gettype($enum);
35
-            if ($this->factory->getConfig(self::CHECK_MODE_TYPE_CAST) && $type == 'array' && $enumType == 'object') {
36
-                if ((object) $element == $enum) {
33
+        foreach ( $schema->enum as $enum ) {
34
+            $enumType = gettype( $enum );
35
+            if ( $this->factory->getConfig( self::CHECK_MODE_TYPE_CAST ) && $type == 'array' && $enumType == 'object' ) {
36
+                if ( (object)$element == $enum ) {
37 37
                     return;
38 38
                 }
39 39
             }
40 40
 
41
-            if ($type === gettype($enum)) {
42
-                if ($type == 'object') {
43
-                    if ($element == $enum) {
41
+            if ( $type === gettype( $enum ) ) {
42
+                if ( $type == 'object' ) {
43
+                    if ( $element == $enum ) {
44 44
                         return;
45 45
                     }
46
-                } elseif ($element === $enum) {
46
+                } elseif ( $element === $enum ) {
47 47
                     return;
48 48
                 }
49 49
             }
50 50
         }
51 51
 
52
-        $this->addError($path, 'Does not have a value in the enumeration ' . json_encode($schema->enum), 'enum', array('enum' => $schema->enum));
52
+        $this->addError( $path, 'Does not have a value in the enumeration ' . json_encode( $schema->enum ), 'enum', array( 'enum' => $schema->enum ) );
53 53
     }
54 54
 }
Please login to merge, or discard this patch.
justinrainbow/json-schema/src/JsonSchema/Constraints/TypeConstraint.php 1 patch
Spacing   +71 added lines, -71 removed lines patch added patch discarded remove patch
@@ -39,29 +39,29 @@  discard block
 block discarded – undo
39 39
     /**
40 40
      * {@inheritdoc}
41 41
      */
42
-    public function check(&$value = null, $schema = null, JsonPointer $path = null, $i = null)
42
+    public function check( &$value = null, $schema = null, JsonPointer $path = null, $i = null )
43 43
     {
44
-        $type = isset($schema->type) ? $schema->type : null;
44
+        $type = isset( $schema->type ) ? $schema->type : null;
45 45
         $isValid = false;
46 46
         $wording = array();
47 47
 
48
-        if (is_array($type)) {
49
-            $this->validateTypesArray($value, $type, $wording, $isValid, $path);
50
-        } elseif (is_object($type)) {
51
-            $this->checkUndefined($value, $type, $path);
48
+        if ( is_array( $type ) ) {
49
+            $this->validateTypesArray( $value, $type, $wording, $isValid, $path );
50
+        } elseif ( is_object( $type ) ) {
51
+            $this->checkUndefined( $value, $type, $path );
52 52
 
53 53
             return;
54 54
         } else {
55
-            $isValid = $this->validateType($value, $type);
55
+            $isValid = $this->validateType( $value, $type );
56 56
         }
57 57
 
58
-        if ($isValid === false) {
59
-            if (!is_array($type)) {
60
-                $this->validateTypeNameWording($type);
61
-                $wording[] = self::$wording[$type];
58
+        if ( $isValid === false ) {
59
+            if ( ! is_array( $type ) ) {
60
+                $this->validateTypeNameWording( $type );
61
+                $wording[ ] = self::$wording[ $type ];
62 62
             }
63
-            $this->addError($path, ucwords(gettype($value)) . ' value found, but ' .
64
-                $this->implodeWith($wording, ', ', 'or') . ' is required', 'type');
63
+            $this->addError( $path, ucwords( gettype( $value ) ) . ' value found, but ' .
64
+                $this->implodeWith( $wording, ', ', 'or' ) . ' is required', 'type' );
65 65
         }
66 66
     }
67 67
 
@@ -76,26 +76,26 @@  discard block
 block discarded – undo
76 76
      * @param bool  $isValid           The current validation value
77 77
      * @param $path
78 78
      */
79
-    protected function validateTypesArray(&$value, array $type, &$validTypesWording, &$isValid, $path)
79
+    protected function validateTypesArray( &$value, array $type, &$validTypesWording, &$isValid, $path )
80 80
     {
81
-        foreach ($type as $tp) {
81
+        foreach ( $type as $tp ) {
82 82
             // $tp can be an object, if it's a schema instead of a simple type, validate it
83 83
             // with a new type constraint
84
-            if (is_object($tp)) {
85
-                if (!$isValid) {
86
-                    $validator = $this->factory->createInstanceFor('type');
84
+            if ( is_object( $tp ) ) {
85
+                if ( ! $isValid ) {
86
+                    $validator = $this->factory->createInstanceFor( 'type' );
87 87
                     $subSchema = new \stdClass();
88 88
                     $subSchema->type = $tp;
89
-                    $validator->check($value, $subSchema, $path, null);
89
+                    $validator->check( $value, $subSchema, $path, null );
90 90
                     $error = $validator->getErrors();
91
-                    $isValid = !(bool) $error;
92
-                    $validTypesWording[] = self::$wording['object'];
91
+                    $isValid = ! (bool)$error;
92
+                    $validTypesWording[ ] = self::$wording[ 'object' ];
93 93
                 }
94 94
             } else {
95
-                $this->validateTypeNameWording($tp);
96
-                $validTypesWording[] = self::$wording[$tp];
97
-                if (!$isValid) {
98
-                    $isValid = $this->validateType($value, $tp);
95
+                $this->validateTypeNameWording( $tp );
96
+                $validTypesWording[ ] = self::$wording[ $tp ];
97
+                if ( ! $isValid ) {
98
+                    $isValid = $this->validateType( $value, $tp );
99 99
                 }
100 100
             }
101 101
         }
@@ -112,16 +112,16 @@  discard block
 block discarded – undo
112 112
      *
113 113
      * @return string
114 114
      */
115
-    protected function implodeWith(array $elements, $delimiter = ', ', $listEnd = false)
115
+    protected function implodeWith( array $elements, $delimiter = ', ', $listEnd = false )
116 116
     {
117
-        if ($listEnd === false || !isset($elements[1])) {
118
-            return implode($delimiter, $elements);
117
+        if ( $listEnd === false || ! isset( $elements[ 1 ] ) ) {
118
+            return implode( $delimiter, $elements );
119 119
         }
120
-        $lastElement  = array_slice($elements, -1);
121
-        $firsElements = join($delimiter, array_slice($elements, 0, -1));
122
-        $implodedElements = array_merge(array($firsElements), $lastElement);
120
+        $lastElement  = array_slice( $elements, -1 );
121
+        $firsElements = join( $delimiter, array_slice( $elements, 0, -1 ) );
122
+        $implodedElements = array_merge( array( $firsElements ), $lastElement );
123 123
 
124
-        return join(" $listEnd ", $implodedElements);
124
+        return join( " $listEnd ", $implodedElements );
125 125
     }
126 126
 
127 127
     /**
@@ -132,14 +132,14 @@  discard block
 block discarded – undo
132 132
      *
133 133
      * @throws StandardUnexpectedValueException
134 134
      */
135
-    protected function validateTypeNameWording($type)
135
+    protected function validateTypeNameWording( $type )
136 136
     {
137
-        if (!isset(self::$wording[$type])) {
137
+        if ( ! isset( self::$wording[ $type ] ) ) {
138 138
             throw new StandardUnexpectedValueException(
139 139
                 sprintf(
140 140
                     'No wording for %s available, expected wordings are: [%s]',
141
-                    var_export($type, true),
142
-                    implode(', ', array_filter(self::$wording)))
141
+                    var_export( $type, true ),
142
+                    implode( ', ', array_filter( self::$wording ) ))
143 143
             );
144 144
         }
145 145
     }
@@ -154,64 +154,64 @@  discard block
 block discarded – undo
154 154
      *
155 155
      * @return bool
156 156
      */
157
-    protected function validateType(&$value, $type)
157
+    protected function validateType( &$value, $type )
158 158
     {
159 159
         //mostly the case for inline schema
160
-        if (!$type) {
160
+        if ( ! $type ) {
161 161
             return true;
162 162
         }
163 163
 
164
-        if ('any' === $type) {
164
+        if ( 'any' === $type ) {
165 165
             return true;
166 166
         }
167 167
 
168
-        if ('object' === $type) {
169
-            return $this->getTypeCheck()->isObject($value);
168
+        if ( 'object' === $type ) {
169
+            return $this->getTypeCheck()->isObject( $value );
170 170
         }
171 171
 
172
-        if ('array' === $type) {
173
-            return $this->getTypeCheck()->isArray($value);
172
+        if ( 'array' === $type ) {
173
+            return $this->getTypeCheck()->isArray( $value );
174 174
         }
175 175
 
176
-        $coerce = $this->factory->getConfig(Constraint::CHECK_MODE_COERCE_TYPES);
176
+        $coerce = $this->factory->getConfig( Constraint::CHECK_MODE_COERCE_TYPES );
177 177
 
178
-        if ('integer' === $type) {
179
-            if ($coerce) {
180
-                $value = $this->toInteger($value);
178
+        if ( 'integer' === $type ) {
179
+            if ( $coerce ) {
180
+                $value = $this->toInteger( $value );
181 181
             }
182 182
 
183
-            return is_int($value);
183
+            return is_int( $value );
184 184
         }
185 185
 
186
-        if ('number' === $type) {
187
-            if ($coerce) {
188
-                $value = $this->toNumber($value);
186
+        if ( 'number' === $type ) {
187
+            if ( $coerce ) {
188
+                $value = $this->toNumber( $value );
189 189
             }
190 190
 
191
-            return is_numeric($value) && !is_string($value);
191
+            return is_numeric( $value ) && ! is_string( $value );
192 192
         }
193 193
 
194
-        if ('boolean' === $type) {
195
-            if ($coerce) {
196
-                $value = $this->toBoolean($value);
194
+        if ( 'boolean' === $type ) {
195
+            if ( $coerce ) {
196
+                $value = $this->toBoolean( $value );
197 197
             }
198 198
 
199
-            return is_bool($value);
199
+            return is_bool( $value );
200 200
         }
201 201
 
202
-        if ('string' === $type) {
203
-            return is_string($value);
202
+        if ( 'string' === $type ) {
203
+            return is_string( $value );
204 204
         }
205 205
 
206
-        if ('email' === $type) {
207
-            return is_string($value);
206
+        if ( 'email' === $type ) {
207
+            return is_string( $value );
208 208
         }
209 209
 
210
-        if ('null' === $type) {
211
-            return is_null($value);
210
+        if ( 'null' === $type ) {
211
+            return is_null( $value );
212 212
         }
213 213
 
214
-        throw new InvalidArgumentException((is_object($value) ? 'object' : $value) . ' is an invalid type for ' . $type);
214
+        throw new InvalidArgumentException( ( is_object( $value ) ? 'object' : $value ) . ' is an invalid type for ' . $type );
215 215
     }
216 216
 
217 217
     /**
@@ -221,13 +221,13 @@  discard block
 block discarded – undo
221 221
      *
222 222
      * @return bool|mixed
223 223
      */
224
-    protected function toBoolean($value)
224
+    protected function toBoolean( $value )
225 225
     {
226
-        if ($value === 'true') {
226
+        if ( $value === 'true' ) {
227 227
             return true;
228 228
         }
229 229
 
230
-        if ($value === 'false') {
230
+        if ( $value === 'false' ) {
231 231
             return false;
232 232
         }
233 233
 
@@ -241,19 +241,19 @@  discard block
 block discarded – undo
241 241
      *
242 242
      * @return int|float|mixed
243 243
      */
244
-    protected function toNumber($value)
244
+    protected function toNumber( $value )
245 245
     {
246
-        if (is_numeric($value)) {
246
+        if ( is_numeric( $value ) ) {
247 247
             return $value + 0; // cast to number
248 248
         }
249 249
 
250 250
         return $value;
251 251
     }
252 252
 
253
-    protected function toInteger($value)
253
+    protected function toInteger( $value )
254 254
     {
255
-        if (is_numeric($value) && (int) $value == $value) {
256
-            return (int) $value; // cast to number
255
+        if ( is_numeric( $value ) && (int)$value == $value ) {
256
+            return (int)$value; // cast to number
257 257
         }
258 258
 
259 259
         return $value;
Please login to merge, or discard this patch.
json-schema/src/JsonSchema/Constraints/UndefinedConstraint.php 1 patch
Spacing   +125 added lines, -125 removed lines patch added patch discarded remove patch
@@ -30,25 +30,25 @@  discard block
 block discarded – undo
30 30
     /**
31 31
      * {@inheritdoc}
32 32
      */
33
-    public function check(&$value, $schema = null, JsonPointer $path = null, $i = null, $fromDefault = false)
33
+    public function check( &$value, $schema = null, JsonPointer $path = null, $i = null, $fromDefault = false )
34 34
     {
35
-        if (is_null($schema) || !is_object($schema)) {
35
+        if ( is_null( $schema ) || ! is_object( $schema ) ) {
36 36
             return;
37 37
         }
38 38
 
39
-        $path = $this->incrementPath($path ?: new JsonPointer(''), $i);
40
-        if ($fromDefault) {
39
+        $path = $this->incrementPath( $path ?: new JsonPointer( '' ), $i );
40
+        if ( $fromDefault ) {
41 41
             $path->setFromDefault();
42 42
         }
43 43
 
44 44
         // check special properties
45
-        $this->validateCommonProperties($value, $schema, $path, $i);
45
+        $this->validateCommonProperties( $value, $schema, $path, $i );
46 46
 
47 47
         // check allOf, anyOf, and oneOf properties
48
-        $this->validateOfProperties($value, $schema, $path, '');
48
+        $this->validateOfProperties( $value, $schema, $path, '' );
49 49
 
50 50
         // check known types
51
-        $this->validateTypes($value, $schema, $path, $i);
51
+        $this->validateTypes( $value, $schema, $path, $i );
52 52
     }
53 53
 
54 54
     /**
@@ -59,41 +59,41 @@  discard block
 block discarded – undo
59 59
      * @param JsonPointer $path
60 60
      * @param string      $i
61 61
      */
62
-    public function validateTypes(&$value, $schema, JsonPointer $path, $i = null)
62
+    public function validateTypes( &$value, $schema, JsonPointer $path, $i = null )
63 63
     {
64 64
         // check array
65
-        if ($this->getTypeCheck()->isArray($value)) {
66
-            $this->checkArray($value, $schema, $path, $i);
65
+        if ( $this->getTypeCheck()->isArray( $value ) ) {
66
+            $this->checkArray( $value, $schema, $path, $i );
67 67
         }
68 68
 
69 69
         // check object
70
-        if (LooseTypeCheck::isObject($value)) { // object processing should always be run on assoc arrays,
70
+        if ( LooseTypeCheck::isObject( $value ) ) { // object processing should always be run on assoc arrays,
71 71
                                                 // so use LooseTypeCheck here even if CHECK_MODE_TYPE_CAST
72 72
                                                 // is not set (i.e. don't use $this->getTypeCheck() here).
73 73
             $this->checkObject(
74 74
                 $value,
75 75
                 $schema,
76 76
                 $path,
77
-                isset($schema->properties) ? $schema->properties : null,
78
-                isset($schema->additionalProperties) ? $schema->additionalProperties : null,
79
-                isset($schema->patternProperties) ? $schema->patternProperties : null,
77
+                isset( $schema->properties ) ? $schema->properties : null,
78
+                isset( $schema->additionalProperties ) ? $schema->additionalProperties : null,
79
+                isset( $schema->patternProperties ) ? $schema->patternProperties : null,
80 80
                 $this->appliedDefaults
81 81
             );
82 82
         }
83 83
 
84 84
         // check string
85
-        if (is_string($value)) {
86
-            $this->checkString($value, $schema, $path, $i);
85
+        if ( is_string( $value ) ) {
86
+            $this->checkString( $value, $schema, $path, $i );
87 87
         }
88 88
 
89 89
         // check numeric
90
-        if (is_numeric($value)) {
91
-            $this->checkNumber($value, $schema, $path, $i);
90
+        if ( is_numeric( $value ) ) {
91
+            $this->checkNumber( $value, $schema, $path, $i );
92 92
         }
93 93
 
94 94
         // check enum
95
-        if (isset($schema->enum)) {
96
-            $this->checkEnum($value, $schema, $path, $i);
95
+        if ( isset( $schema->enum ) ) {
96
+            $this->checkEnum( $value, $schema, $path, $i );
97 97
         }
98 98
     }
99 99
 
@@ -105,45 +105,45 @@  discard block
 block discarded – undo
105 105
      * @param JsonPointer $path
106 106
      * @param string      $i
107 107
      */
108
-    protected function validateCommonProperties(&$value, $schema, JsonPointer $path, $i = '')
108
+    protected function validateCommonProperties( &$value, $schema, JsonPointer $path, $i = '' )
109 109
     {
110 110
         // if it extends another schema, it must pass that schema as well
111
-        if (isset($schema->extends)) {
112
-            if (is_string($schema->extends)) {
113
-                $schema->extends = $this->validateUri($schema, $schema->extends);
111
+        if ( isset( $schema->extends ) ) {
112
+            if ( is_string( $schema->extends ) ) {
113
+                $schema->extends = $this->validateUri( $schema, $schema->extends );
114 114
             }
115
-            if (is_array($schema->extends)) {
116
-                foreach ($schema->extends as $extends) {
117
-                    $this->checkUndefined($value, $extends, $path, $i);
115
+            if ( is_array( $schema->extends ) ) {
116
+                foreach ( $schema->extends as $extends ) {
117
+                    $this->checkUndefined( $value, $extends, $path, $i );
118 118
                 }
119 119
             } else {
120
-                $this->checkUndefined($value, $schema->extends, $path, $i);
120
+                $this->checkUndefined( $value, $schema->extends, $path, $i );
121 121
             }
122 122
         }
123 123
 
124 124
         // Apply default values from schema
125
-        if (!$path->fromDefault()) {
126
-            $this->applyDefaultValues($value, $schema, $path);
125
+        if ( ! $path->fromDefault() ) {
126
+            $this->applyDefaultValues( $value, $schema, $path );
127 127
         }
128 128
 
129 129
         // Verify required values
130
-        if ($this->getTypeCheck()->isObject($value)) {
131
-            if (!($value instanceof self) && isset($schema->required) && is_array($schema->required)) {
130
+        if ( $this->getTypeCheck()->isObject( $value ) ) {
131
+            if ( ! ( $value instanceof self ) && isset( $schema->required ) && is_array( $schema->required ) ) {
132 132
                 // Draft 4 - Required is an array of strings - e.g. "required": ["foo", ...]
133
-                foreach ($schema->required as $required) {
134
-                    if (!$this->getTypeCheck()->propertyExists($value, $required)) {
133
+                foreach ( $schema->required as $required ) {
134
+                    if ( ! $this->getTypeCheck()->propertyExists( $value, $required ) ) {
135 135
                         $this->addError(
136
-                            $this->incrementPath($path ?: new JsonPointer(''), $required),
136
+                            $this->incrementPath( $path ?: new JsonPointer( '' ), $required ),
137 137
                             'The property ' . $required . ' is required',
138 138
                             'required'
139 139
                         );
140 140
                     }
141 141
                 }
142
-            } elseif (isset($schema->required) && !is_array($schema->required)) {
142
+            } elseif ( isset( $schema->required ) && ! is_array( $schema->required ) ) {
143 143
                 // Draft 3 - Required attribute - e.g. "foo": {"type": "string", "required": true}
144
-                if ($schema->required && $value instanceof self) {
144
+                if ( $schema->required && $value instanceof self ) {
145 145
                     $propertyPaths = $path->getPropertyPaths();
146
-                    $propertyName = end($propertyPaths);
146
+                    $propertyName = end( $propertyPaths );
147 147
                     $this->addError(
148 148
                         $path,
149 149
                         'The property ' . $propertyName . ' is required',
@@ -153,48 +153,48 @@  discard block
 block discarded – undo
153 153
             } else {
154 154
                 // if the value is both undefined and not required, skip remaining checks
155 155
                 // in this method which assume an actual, defined instance when validating.
156
-                if ($value instanceof self) {
156
+                if ( $value instanceof self ) {
157 157
                     return;
158 158
                 }
159 159
             }
160 160
         }
161 161
 
162 162
         // Verify type
163
-        if (!($value instanceof self)) {
164
-            $this->checkType($value, $schema, $path, $i);
163
+        if ( ! ( $value instanceof self ) ) {
164
+            $this->checkType( $value, $schema, $path, $i );
165 165
         }
166 166
 
167 167
         // Verify disallowed items
168
-        if (isset($schema->disallow)) {
168
+        if ( isset( $schema->disallow ) ) {
169 169
             $initErrors = $this->getErrors();
170 170
 
171 171
             $typeSchema = new \stdClass();
172 172
             $typeSchema->type = $schema->disallow;
173
-            $this->checkType($value, $typeSchema, $path);
173
+            $this->checkType( $value, $typeSchema, $path );
174 174
 
175 175
             // if no new errors were raised it must be a disallowed value
176
-            if (count($this->getErrors()) == count($initErrors)) {
177
-                $this->addError($path, 'Disallowed value was matched', 'disallow');
176
+            if ( count( $this->getErrors() ) == count( $initErrors ) ) {
177
+                $this->addError( $path, 'Disallowed value was matched', 'disallow' );
178 178
             } else {
179 179
                 $this->errors = $initErrors;
180 180
             }
181 181
         }
182 182
 
183
-        if (isset($schema->not)) {
183
+        if ( isset( $schema->not ) ) {
184 184
             $initErrors = $this->getErrors();
185
-            $this->checkUndefined($value, $schema->not, $path, $i);
185
+            $this->checkUndefined( $value, $schema->not, $path, $i );
186 186
 
187 187
             // if no new errors were raised then the instance validated against the "not" schema
188
-            if (count($this->getErrors()) == count($initErrors)) {
189
-                $this->addError($path, 'Matched a schema which it should not', 'not');
188
+            if ( count( $this->getErrors() ) == count( $initErrors ) ) {
189
+                $this->addError( $path, 'Matched a schema which it should not', 'not' );
190 190
             } else {
191 191
                 $this->errors = $initErrors;
192 192
             }
193 193
         }
194 194
 
195 195
         // Verify that dependencies are met
196
-        if (isset($schema->dependencies) && $this->getTypeCheck()->isObject($value)) {
197
-            $this->validateDependencies($value, $schema->dependencies, $path);
196
+        if ( isset( $schema->dependencies ) && $this->getTypeCheck()->isObject( $value ) ) {
197
+            $this->validateDependencies( $value, $schema->dependencies, $path );
198 198
         }
199 199
     }
200 200
 
@@ -207,23 +207,23 @@  discard block
 block discarded – undo
207 207
      *
208 208
      * @return bool
209 209
      */
210
-    private function shouldApplyDefaultValue($requiredOnly, $schema, $name = null, $parentSchema = null)
210
+    private function shouldApplyDefaultValue( $requiredOnly, $schema, $name = null, $parentSchema = null )
211 211
     {
212 212
         // required-only mode is off
213
-        if (!$requiredOnly) {
213
+        if ( ! $requiredOnly ) {
214 214
             return true;
215 215
         }
216 216
         // draft-04 required is set
217 217
         if (
218 218
             $name !== null
219
-            && isset($parentSchema->required)
220
-            && is_array($parentSchema->required)
221
-            && in_array($name, $parentSchema->required)
219
+            && isset( $parentSchema->required )
220
+            && is_array( $parentSchema->required )
221
+            && in_array( $name, $parentSchema->required )
222 222
         ) {
223 223
             return true;
224 224
         }
225 225
         // draft-03 required is set
226
-        if (isset($schema->required) && !is_array($schema->required) && $schema->required) {
226
+        if ( isset( $schema->required ) && ! is_array( $schema->required ) && $schema->required ) {
227 227
             return true;
228 228
         }
229 229
         // default case
@@ -237,61 +237,61 @@  discard block
 block discarded – undo
237 237
      * @param mixed       $schema
238 238
      * @param JsonPointer $path
239 239
      */
240
-    protected function applyDefaultValues(&$value, $schema, $path)
240
+    protected function applyDefaultValues( &$value, $schema, $path )
241 241
     {
242 242
         // only apply defaults if feature is enabled
243
-        if (!$this->factory->getConfig(self::CHECK_MODE_APPLY_DEFAULTS)) {
243
+        if ( ! $this->factory->getConfig( self::CHECK_MODE_APPLY_DEFAULTS ) ) {
244 244
             return;
245 245
         }
246 246
 
247 247
         // apply defaults if appropriate
248
-        $requiredOnly = $this->factory->getConfig(self::CHECK_MODE_ONLY_REQUIRED_DEFAULTS);
249
-        if (isset($schema->properties) && LooseTypeCheck::isObject($value)) {
248
+        $requiredOnly = $this->factory->getConfig( self::CHECK_MODE_ONLY_REQUIRED_DEFAULTS );
249
+        if ( isset( $schema->properties ) && LooseTypeCheck::isObject( $value ) ) {
250 250
             // $value is an object or assoc array, and properties are defined - treat as an object
251
-            foreach ($schema->properties as $currentProperty => $propertyDefinition) {
252
-                $propertyDefinition = $this->factory->getSchemaStorage()->resolveRefSchema($propertyDefinition);
251
+            foreach ( $schema->properties as $currentProperty => $propertyDefinition ) {
252
+                $propertyDefinition = $this->factory->getSchemaStorage()->resolveRefSchema( $propertyDefinition );
253 253
                 if (
254
-                    !LooseTypeCheck::propertyExists($value, $currentProperty)
255
-                    && property_exists($propertyDefinition, 'default')
256
-                    && $this->shouldApplyDefaultValue($requiredOnly, $propertyDefinition, $currentProperty, $schema)
254
+                    ! LooseTypeCheck::propertyExists( $value, $currentProperty )
255
+                    && property_exists( $propertyDefinition, 'default' )
256
+                    && $this->shouldApplyDefaultValue( $requiredOnly, $propertyDefinition, $currentProperty, $schema )
257 257
                 ) {
258 258
                     // assign default value
259
-                    if (is_object($propertyDefinition->default)) {
260
-                        LooseTypeCheck::propertySet($value, $currentProperty, clone $propertyDefinition->default);
259
+                    if ( is_object( $propertyDefinition->default ) ) {
260
+                        LooseTypeCheck::propertySet( $value, $currentProperty, clone $propertyDefinition->default );
261 261
                     } else {
262
-                        LooseTypeCheck::propertySet($value, $currentProperty, $propertyDefinition->default);
262
+                        LooseTypeCheck::propertySet( $value, $currentProperty, $propertyDefinition->default );
263 263
                     }
264
-                    $this->appliedDefaults[] = $currentProperty;
264
+                    $this->appliedDefaults[ ] = $currentProperty;
265 265
                 }
266 266
             }
267
-        } elseif (isset($schema->items) && LooseTypeCheck::isArray($value)) {
267
+        } elseif ( isset( $schema->items ) && LooseTypeCheck::isArray( $value ) ) {
268 268
             $items = array();
269
-            if (LooseTypeCheck::isArray($schema->items)) {
269
+            if ( LooseTypeCheck::isArray( $schema->items ) ) {
270 270
                 $items = $schema->items;
271
-            } elseif (isset($schema->minItems) && count($value) < $schema->minItems) {
272
-                $items = array_fill(count($value), $schema->minItems - count($value), $schema->items);
271
+            } elseif ( isset( $schema->minItems ) && count( $value ) < $schema->minItems ) {
272
+                $items = array_fill( count( $value ), $schema->minItems - count( $value ), $schema->items );
273 273
             }
274 274
             // $value is an array, and items are defined - treat as plain array
275
-            foreach ($items as $currentItem => $itemDefinition) {
276
-                $itemDefinition = $this->factory->getSchemaStorage()->resolveRefSchema($itemDefinition);
275
+            foreach ( $items as $currentItem => $itemDefinition ) {
276
+                $itemDefinition = $this->factory->getSchemaStorage()->resolveRefSchema( $itemDefinition );
277 277
                 if (
278
-                    !array_key_exists($currentItem, $value)
279
-                    && property_exists($itemDefinition, 'default')
280
-                    && $this->shouldApplyDefaultValue($requiredOnly, $itemDefinition)) {
281
-                    if (is_object($itemDefinition->default)) {
282
-                        $value[$currentItem] = clone $itemDefinition->default;
278
+                    ! array_key_exists( $currentItem, $value )
279
+                    && property_exists( $itemDefinition, 'default' )
280
+                    && $this->shouldApplyDefaultValue( $requiredOnly, $itemDefinition )) {
281
+                    if ( is_object( $itemDefinition->default ) ) {
282
+                        $value[ $currentItem ] = clone $itemDefinition->default;
283 283
                     } else {
284
-                        $value[$currentItem] = $itemDefinition->default;
284
+                        $value[ $currentItem ] = $itemDefinition->default;
285 285
                     }
286 286
                 }
287 287
                 $path->setFromDefault();
288 288
             }
289 289
         } elseif (
290 290
             $value instanceof self
291
-            && property_exists($schema, 'default')
292
-            && $this->shouldApplyDefaultValue($requiredOnly, $schema)) {
291
+            && property_exists( $schema, 'default' )
292
+            && $this->shouldApplyDefaultValue( $requiredOnly, $schema )) {
293 293
             // $value is a leaf, not a container - apply the default directly
294
-            $value = is_object($schema->default) ? clone $schema->default : $schema->default;
294
+            $value = is_object( $schema->default ) ? clone $schema->default : $schema->default;
295 295
             $path->setFromDefault();
296 296
         }
297 297
     }
@@ -304,67 +304,67 @@  discard block
 block discarded – undo
304 304
      * @param JsonPointer $path
305 305
      * @param string      $i
306 306
      */
307
-    protected function validateOfProperties(&$value, $schema, JsonPointer $path, $i = '')
307
+    protected function validateOfProperties( &$value, $schema, JsonPointer $path, $i = '' )
308 308
     {
309 309
         // Verify type
310
-        if ($value instanceof self) {
310
+        if ( $value instanceof self ) {
311 311
             return;
312 312
         }
313 313
 
314
-        if (isset($schema->allOf)) {
314
+        if ( isset( $schema->allOf ) ) {
315 315
             $isValid = true;
316
-            foreach ($schema->allOf as $allOf) {
316
+            foreach ( $schema->allOf as $allOf ) {
317 317
                 $initErrors = $this->getErrors();
318
-                $this->checkUndefined($value, $allOf, $path, $i);
319
-                $isValid = $isValid && (count($this->getErrors()) == count($initErrors));
318
+                $this->checkUndefined( $value, $allOf, $path, $i );
319
+                $isValid = $isValid && ( count( $this->getErrors() ) == count( $initErrors ) );
320 320
             }
321
-            if (!$isValid) {
322
-                $this->addError($path, 'Failed to match all schemas', 'allOf');
321
+            if ( ! $isValid ) {
322
+                $this->addError( $path, 'Failed to match all schemas', 'allOf' );
323 323
             }
324 324
         }
325 325
 
326
-        if (isset($schema->anyOf)) {
326
+        if ( isset( $schema->anyOf ) ) {
327 327
             $isValid = false;
328 328
             $startErrors = $this->getErrors();
329 329
             $caughtException = null;
330
-            foreach ($schema->anyOf as $anyOf) {
330
+            foreach ( $schema->anyOf as $anyOf ) {
331 331
                 $initErrors = $this->getErrors();
332 332
                 try {
333
-                    $this->checkUndefined($value, $anyOf, $path, $i);
334
-                    if ($isValid = (count($this->getErrors()) == count($initErrors))) {
333
+                    $this->checkUndefined( $value, $anyOf, $path, $i );
334
+                    if ( $isValid = ( count( $this->getErrors() ) == count( $initErrors ) ) ) {
335 335
                         break;
336 336
                     }
337
-                } catch (ValidationException $e) {
337
+                } catch ( ValidationException $e ) {
338 338
                     $isValid = false;
339 339
                 }
340 340
             }
341
-            if (!$isValid) {
342
-                $this->addError($path, 'Failed to match at least one schema', 'anyOf');
341
+            if ( ! $isValid ) {
342
+                $this->addError( $path, 'Failed to match at least one schema', 'anyOf' );
343 343
             } else {
344 344
                 $this->errors = $startErrors;
345 345
             }
346 346
         }
347 347
 
348
-        if (isset($schema->oneOf)) {
348
+        if ( isset( $schema->oneOf ) ) {
349 349
             $allErrors = array();
350 350
             $matchedSchemas = 0;
351 351
             $startErrors = $this->getErrors();
352
-            foreach ($schema->oneOf as $oneOf) {
352
+            foreach ( $schema->oneOf as $oneOf ) {
353 353
                 try {
354 354
                     $this->errors = array();
355
-                    $this->checkUndefined($value, $oneOf, $path, $i);
356
-                    if (count($this->getErrors()) == 0) {
355
+                    $this->checkUndefined( $value, $oneOf, $path, $i );
356
+                    if ( count( $this->getErrors() ) == 0 ) {
357 357
                         $matchedSchemas++;
358 358
                     }
359
-                    $allErrors = array_merge($allErrors, array_values($this->getErrors()));
360
-                } catch (ValidationException $e) {
359
+                    $allErrors = array_merge( $allErrors, array_values( $this->getErrors() ) );
360
+                } catch ( ValidationException $e ) {
361 361
                     // deliberately do nothing here - validation failed, but we want to check
362 362
                     // other schema options in the OneOf field.
363 363
                 }
364 364
             }
365
-            if ($matchedSchemas !== 1) {
366
-                $this->addErrors(array_merge($allErrors, $startErrors));
367
-                $this->addError($path, 'Failed to match exactly one schema', 'oneOf');
365
+            if ( $matchedSchemas !== 1 ) {
366
+                $this->addErrors( array_merge( $allErrors, $startErrors ) );
367
+                $this->addError( $path, 'Failed to match exactly one schema', 'oneOf' );
368 368
             } else {
369 369
                 $this->errors = $startErrors;
370 370
             }
@@ -379,39 +379,39 @@  discard block
 block discarded – undo
379 379
      * @param JsonPointer $path
380 380
      * @param string      $i
381 381
      */
382
-    protected function validateDependencies($value, $dependencies, JsonPointer $path, $i = '')
382
+    protected function validateDependencies( $value, $dependencies, JsonPointer $path, $i = '' )
383 383
     {
384
-        foreach ($dependencies as $key => $dependency) {
385
-            if ($this->getTypeCheck()->propertyExists($value, $key)) {
386
-                if (is_string($dependency)) {
384
+        foreach ( $dependencies as $key => $dependency ) {
385
+            if ( $this->getTypeCheck()->propertyExists( $value, $key ) ) {
386
+                if ( is_string( $dependency ) ) {
387 387
                     // Draft 3 string is allowed - e.g. "dependencies": {"bar": "foo"}
388
-                    if (!$this->getTypeCheck()->propertyExists($value, $dependency)) {
389
-                        $this->addError($path, "$key depends on $dependency and $dependency is missing", 'dependencies');
388
+                    if ( ! $this->getTypeCheck()->propertyExists( $value, $dependency ) ) {
389
+                        $this->addError( $path, "$key depends on $dependency and $dependency is missing", 'dependencies' );
390 390
                     }
391
-                } elseif (is_array($dependency)) {
391
+                } elseif ( is_array( $dependency ) ) {
392 392
                     // Draft 4 must be an array - e.g. "dependencies": {"bar": ["foo"]}
393
-                    foreach ($dependency as $d) {
394
-                        if (!$this->getTypeCheck()->propertyExists($value, $d)) {
395
-                            $this->addError($path, "$key depends on $d and $d is missing", 'dependencies');
393
+                    foreach ( $dependency as $d ) {
394
+                        if ( ! $this->getTypeCheck()->propertyExists( $value, $d ) ) {
395
+                            $this->addError( $path, "$key depends on $d and $d is missing", 'dependencies' );
396 396
                         }
397 397
                     }
398
-                } elseif (is_object($dependency)) {
398
+                } elseif ( is_object( $dependency ) ) {
399 399
                     // Schema - e.g. "dependencies": {"bar": {"properties": {"foo": {...}}}}
400
-                    $this->checkUndefined($value, $dependency, $path, $i);
400
+                    $this->checkUndefined( $value, $dependency, $path, $i );
401 401
                 }
402 402
             }
403 403
         }
404 404
     }
405 405
 
406
-    protected function validateUri($schema, $schemaUri = null)
406
+    protected function validateUri( $schema, $schemaUri = null )
407 407
     {
408 408
         $resolver = new UriResolver();
409 409
         $retriever = $this->factory->getUriRetriever();
410 410
 
411 411
         $jsonSchema = null;
412
-        if ($resolver->isValid($schemaUri)) {
413
-            $schemaId = property_exists($schema, 'id') ? $schema->id : null;
414
-            $jsonSchema = $retriever->retrieve($schemaId, $schemaUri);
412
+        if ( $resolver->isValid( $schemaUri ) ) {
413
+            $schemaId = property_exists( $schema, 'id' ) ? $schema->id : null;
414
+            $jsonSchema = $retriever->retrieve( $schemaId, $schemaUri );
415 415
         }
416 416
 
417 417
         return $jsonSchema;
Please login to merge, or discard this patch.
justinrainbow/json-schema/src/JsonSchema/Constraints/NumberConstraint.php 1 patch
Spacing   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -22,54 +22,54 @@
 block discarded – undo
22 22
     /**
23 23
      * {@inheritdoc}
24 24
      */
25
-    public function check(&$element, $schema = null, JsonPointer $path = null, $i = null)
25
+    public function check( &$element, $schema = null, JsonPointer $path = null, $i = null )
26 26
     {
27 27
         // Verify minimum
28
-        if (isset($schema->exclusiveMinimum)) {
29
-            if (isset($schema->minimum)) {
30
-                if ($schema->exclusiveMinimum && $element <= $schema->minimum) {
31
-                    $this->addError($path, 'Must have a minimum value of ' . $schema->minimum, 'exclusiveMinimum', array('minimum' => $schema->minimum));
32
-                } elseif ($element < $schema->minimum) {
33
-                    $this->addError($path, 'Must have a minimum value of ' . $schema->minimum, 'minimum', array('minimum' => $schema->minimum));
28
+        if ( isset( $schema->exclusiveMinimum ) ) {
29
+            if ( isset( $schema->minimum ) ) {
30
+                if ( $schema->exclusiveMinimum && $element <= $schema->minimum ) {
31
+                    $this->addError( $path, 'Must have a minimum value of ' . $schema->minimum, 'exclusiveMinimum', array( 'minimum' => $schema->minimum ) );
32
+                } elseif ( $element < $schema->minimum ) {
33
+                    $this->addError( $path, 'Must have a minimum value of ' . $schema->minimum, 'minimum', array( 'minimum' => $schema->minimum ) );
34 34
                 }
35 35
             } else {
36
-                $this->addError($path, 'Use of exclusiveMinimum requires presence of minimum', 'missingMinimum');
36
+                $this->addError( $path, 'Use of exclusiveMinimum requires presence of minimum', 'missingMinimum' );
37 37
             }
38
-        } elseif (isset($schema->minimum) && $element < $schema->minimum) {
39
-            $this->addError($path, 'Must have a minimum value of ' . $schema->minimum, 'minimum', array('minimum' => $schema->minimum));
38
+        } elseif ( isset( $schema->minimum ) && $element < $schema->minimum ) {
39
+            $this->addError( $path, 'Must have a minimum value of ' . $schema->minimum, 'minimum', array( 'minimum' => $schema->minimum ) );
40 40
         }
41 41
 
42 42
         // Verify maximum
43
-        if (isset($schema->exclusiveMaximum)) {
44
-            if (isset($schema->maximum)) {
45
-                if ($schema->exclusiveMaximum && $element >= $schema->maximum) {
46
-                    $this->addError($path, 'Must have a maximum value of ' . $schema->maximum, 'exclusiveMaximum', array('maximum' => $schema->maximum));
47
-                } elseif ($element > $schema->maximum) {
48
-                    $this->addError($path, 'Must have a maximum value of ' . $schema->maximum, 'maximum', array('maximum' => $schema->maximum));
43
+        if ( isset( $schema->exclusiveMaximum ) ) {
44
+            if ( isset( $schema->maximum ) ) {
45
+                if ( $schema->exclusiveMaximum && $element >= $schema->maximum ) {
46
+                    $this->addError( $path, 'Must have a maximum value of ' . $schema->maximum, 'exclusiveMaximum', array( 'maximum' => $schema->maximum ) );
47
+                } elseif ( $element > $schema->maximum ) {
48
+                    $this->addError( $path, 'Must have a maximum value of ' . $schema->maximum, 'maximum', array( 'maximum' => $schema->maximum ) );
49 49
                 }
50 50
             } else {
51
-                $this->addError($path, 'Use of exclusiveMaximum requires presence of maximum', 'missingMaximum');
51
+                $this->addError( $path, 'Use of exclusiveMaximum requires presence of maximum', 'missingMaximum' );
52 52
             }
53
-        } elseif (isset($schema->maximum) && $element > $schema->maximum) {
54
-            $this->addError($path, 'Must have a maximum value of ' . $schema->maximum, 'maximum', array('maximum' => $schema->maximum));
53
+        } elseif ( isset( $schema->maximum ) && $element > $schema->maximum ) {
54
+            $this->addError( $path, 'Must have a maximum value of ' . $schema->maximum, 'maximum', array( 'maximum' => $schema->maximum ) );
55 55
         }
56 56
 
57 57
         // Verify divisibleBy - Draft v3
58
-        if (isset($schema->divisibleBy) && $this->fmod($element, $schema->divisibleBy) != 0) {
59
-            $this->addError($path, 'Is not divisible by ' . $schema->divisibleBy, 'divisibleBy', array('divisibleBy' => $schema->divisibleBy));
58
+        if ( isset( $schema->divisibleBy ) && $this->fmod( $element, $schema->divisibleBy ) != 0 ) {
59
+            $this->addError( $path, 'Is not divisible by ' . $schema->divisibleBy, 'divisibleBy', array( 'divisibleBy' => $schema->divisibleBy ) );
60 60
         }
61 61
 
62 62
         // Verify multipleOf - Draft v4
63
-        if (isset($schema->multipleOf) && $this->fmod($element, $schema->multipleOf) != 0) {
64
-            $this->addError($path, 'Must be a multiple of ' . $schema->multipleOf, 'multipleOf', array('multipleOf' => $schema->multipleOf));
63
+        if ( isset( $schema->multipleOf ) && $this->fmod( $element, $schema->multipleOf ) != 0 ) {
64
+            $this->addError( $path, 'Must be a multiple of ' . $schema->multipleOf, 'multipleOf', array( 'multipleOf' => $schema->multipleOf ) );
65 65
         }
66 66
 
67
-        $this->checkFormat($element, $schema, $path, $i);
67
+        $this->checkFormat( $element, $schema, $path, $i );
68 68
     }
69 69
 
70
-    private function fmod($number1, $number2)
70
+    private function fmod( $number1, $number2 )
71 71
     {
72
-        $modulus = ($number1 - round($number1 / $number2) * $number2);
72
+        $modulus = ( $number1 - round( $number1 / $number2 ) * $number2 );
73 73
         $precision = 0.0000000001;
74 74
 
75 75
         if (-$precision < $modulus && $modulus < $precision) {
Please login to merge, or discard this patch.
justinrainbow/json-schema/src/JsonSchema/Constraints/FormatConstraint.php 1 patch
Spacing   +61 added lines, -61 removed lines patch added patch discarded remove patch
@@ -24,121 +24,121 @@  discard block
 block discarded – undo
24 24
     /**
25 25
      * {@inheritdoc}
26 26
      */
27
-    public function check(&$element, $schema = null, JsonPointer $path = null, $i = null)
27
+    public function check( &$element, $schema = null, JsonPointer $path = null, $i = null )
28 28
     {
29
-        if (!isset($schema->format) || $this->factory->getConfig(self::CHECK_MODE_DISABLE_FORMAT)) {
29
+        if ( ! isset( $schema->format ) || $this->factory->getConfig( self::CHECK_MODE_DISABLE_FORMAT ) ) {
30 30
             return;
31 31
         }
32 32
 
33
-        switch ($schema->format) {
33
+        switch ( $schema->format ) {
34 34
             case 'date':
35
-                if (!$date = $this->validateDateTime($element, 'Y-m-d')) {
36
-                    $this->addError($path, sprintf('Invalid date %s, expected format YYYY-MM-DD', json_encode($element)), 'format', array('format' => $schema->format));
35
+                if ( ! $date = $this->validateDateTime( $element, 'Y-m-d' ) ) {
36
+                    $this->addError( $path, sprintf( 'Invalid date %s, expected format YYYY-MM-DD', json_encode( $element ) ), 'format', array( 'format' => $schema->format ) );
37 37
                 }
38 38
                 break;
39 39
 
40 40
             case 'time':
41
-                if (!$this->validateDateTime($element, 'H:i:s')) {
42
-                    $this->addError($path, sprintf('Invalid time %s, expected format hh:mm:ss', json_encode($element)), 'format', array('format' => $schema->format));
41
+                if ( ! $this->validateDateTime( $element, 'H:i:s' ) ) {
42
+                    $this->addError( $path, sprintf( 'Invalid time %s, expected format hh:mm:ss', json_encode( $element ) ), 'format', array( 'format' => $schema->format ) );
43 43
                 }
44 44
                 break;
45 45
 
46 46
             case 'date-time':
47
-                if (null === Rfc3339::createFromString($element)) {
48
-                    $this->addError($path, sprintf('Invalid date-time %s, expected format YYYY-MM-DDThh:mm:ssZ or YYYY-MM-DDThh:mm:ss+hh:mm', json_encode($element)), 'format', array('format' => $schema->format));
47
+                if ( null === Rfc3339::createFromString( $element ) ) {
48
+                    $this->addError( $path, sprintf( 'Invalid date-time %s, expected format YYYY-MM-DDThh:mm:ssZ or YYYY-MM-DDThh:mm:ss+hh:mm', json_encode( $element ) ), 'format', array( 'format' => $schema->format ) );
49 49
                 }
50 50
                 break;
51 51
 
52 52
             case 'utc-millisec':
53
-                if (!$this->validateDateTime($element, 'U')) {
54
-                    $this->addError($path, sprintf('Invalid time %s, expected integer of milliseconds since Epoch', json_encode($element)), 'format', array('format' => $schema->format));
53
+                if ( ! $this->validateDateTime( $element, 'U' ) ) {
54
+                    $this->addError( $path, sprintf( 'Invalid time %s, expected integer of milliseconds since Epoch', json_encode( $element ) ), 'format', array( 'format' => $schema->format ) );
55 55
                 }
56 56
                 break;
57 57
 
58 58
             case 'regex':
59
-                if (!$this->validateRegex($element)) {
60
-                    $this->addError($path, 'Invalid regex format ' . $element, 'format', array('format' => $schema->format));
59
+                if ( ! $this->validateRegex( $element ) ) {
60
+                    $this->addError( $path, 'Invalid regex format ' . $element, 'format', array( 'format' => $schema->format ) );
61 61
                 }
62 62
                 break;
63 63
 
64 64
             case 'color':
65
-                if (!$this->validateColor($element)) {
66
-                    $this->addError($path, 'Invalid color', 'format', array('format' => $schema->format));
65
+                if ( ! $this->validateColor( $element ) ) {
66
+                    $this->addError( $path, 'Invalid color', 'format', array( 'format' => $schema->format ) );
67 67
                 }
68 68
                 break;
69 69
 
70 70
             case 'style':
71
-                if (!$this->validateStyle($element)) {
72
-                    $this->addError($path, 'Invalid style', 'format', array('format' => $schema->format));
71
+                if ( ! $this->validateStyle( $element ) ) {
72
+                    $this->addError( $path, 'Invalid style', 'format', array( 'format' => $schema->format ) );
73 73
                 }
74 74
                 break;
75 75
 
76 76
             case 'phone':
77
-                if (!$this->validatePhone($element)) {
78
-                    $this->addError($path, 'Invalid phone number', 'format', array('format' => $schema->format));
77
+                if ( ! $this->validatePhone( $element ) ) {
78
+                    $this->addError( $path, 'Invalid phone number', 'format', array( 'format' => $schema->format ) );
79 79
                 }
80 80
                 break;
81 81
 
82 82
             case 'uri':
83
-                if (null === filter_var($element, FILTER_VALIDATE_URL, FILTER_NULL_ON_FAILURE)) {
84
-                    $this->addError($path, 'Invalid URL format', 'format', array('format' => $schema->format));
83
+                if ( null === filter_var( $element, FILTER_VALIDATE_URL, FILTER_NULL_ON_FAILURE ) ) {
84
+                    $this->addError( $path, 'Invalid URL format', 'format', array( 'format' => $schema->format ) );
85 85
                 }
86 86
                 break;
87 87
 
88 88
             case 'uriref':
89 89
             case 'uri-reference':
90
-                if (null === filter_var($element, FILTER_VALIDATE_URL, FILTER_NULL_ON_FAILURE)) {
90
+                if ( null === filter_var( $element, FILTER_VALIDATE_URL, FILTER_NULL_ON_FAILURE ) ) {
91 91
                     // FILTER_VALIDATE_URL does not conform to RFC-3986, and cannot handle relative URLs, but
92 92
                     // the json-schema spec uses RFC-3986, so need a bit of hackery to properly validate them.
93 93
                     // See https://tools.ietf.org/html/rfc3986#section-4.2 for additional information.
94
-                    if (substr($element, 0, 2) === '//') { // network-path reference
95
-                        $validURL = filter_var('scheme:' . $element, FILTER_VALIDATE_URL, FILTER_NULL_ON_FAILURE);
96
-                    } elseif (substr($element, 0, 1) === '/') { // absolute-path reference
97
-                        $validURL = filter_var('scheme://host' . $element, FILTER_VALIDATE_URL, FILTER_NULL_ON_FAILURE);
98
-                    } elseif (strlen($element)) { // relative-path reference
99
-                        $pathParts = explode('/', $element, 2);
100
-                        if (strpos($pathParts[0], ':') !== false) {
94
+                    if ( substr( $element, 0, 2 ) === '//' ) { // network-path reference
95
+                        $validURL = filter_var( 'scheme:' . $element, FILTER_VALIDATE_URL, FILTER_NULL_ON_FAILURE );
96
+                    } elseif ( substr( $element, 0, 1 ) === '/' ) { // absolute-path reference
97
+                        $validURL = filter_var( 'scheme://host' . $element, FILTER_VALIDATE_URL, FILTER_NULL_ON_FAILURE );
98
+                    } elseif ( strlen( $element ) ) { // relative-path reference
99
+                        $pathParts = explode( '/', $element, 2 );
100
+                        if ( strpos( $pathParts[ 0 ], ':' ) !== false ) {
101 101
                             $validURL = null;
102 102
                         } else {
103
-                            $validURL = filter_var('scheme://host/' . $element, FILTER_VALIDATE_URL, FILTER_NULL_ON_FAILURE);
103
+                            $validURL = filter_var( 'scheme://host/' . $element, FILTER_VALIDATE_URL, FILTER_NULL_ON_FAILURE );
104 104
                         }
105 105
                     } else {
106 106
                         $validURL = null;
107 107
                     }
108
-                    if ($validURL === null) {
109
-                        $this->addError($path, 'Invalid URL format', 'format', array('format' => $schema->format));
108
+                    if ( $validURL === null ) {
109
+                        $this->addError( $path, 'Invalid URL format', 'format', array( 'format' => $schema->format ) );
110 110
                     }
111 111
                 }
112 112
                 break;
113 113
 
114 114
             case 'email':
115 115
                 $filterFlags = FILTER_NULL_ON_FAILURE;
116
-                if (defined('FILTER_FLAG_EMAIL_UNICODE')) {
116
+                if ( defined( 'FILTER_FLAG_EMAIL_UNICODE' ) ) {
117 117
                     // Only available from PHP >= 7.1.0, so ignore it for coverage checks
118
-                    $filterFlags |= constant('FILTER_FLAG_EMAIL_UNICODE'); // @codeCoverageIgnore
118
+                    $filterFlags |= constant( 'FILTER_FLAG_EMAIL_UNICODE' ); // @codeCoverageIgnore
119 119
                 }
120
-                if (null === filter_var($element, FILTER_VALIDATE_EMAIL, $filterFlags)) {
121
-                    $this->addError($path, 'Invalid email', 'format', array('format' => $schema->format));
120
+                if ( null === filter_var( $element, FILTER_VALIDATE_EMAIL, $filterFlags ) ) {
121
+                    $this->addError( $path, 'Invalid email', 'format', array( 'format' => $schema->format ) );
122 122
                 }
123 123
                 break;
124 124
 
125 125
             case 'ip-address':
126 126
             case 'ipv4':
127
-                if (null === filter_var($element, FILTER_VALIDATE_IP, FILTER_NULL_ON_FAILURE | FILTER_FLAG_IPV4)) {
128
-                    $this->addError($path, 'Invalid IP address', 'format', array('format' => $schema->format));
127
+                if ( null === filter_var( $element, FILTER_VALIDATE_IP, FILTER_NULL_ON_FAILURE | FILTER_FLAG_IPV4 ) ) {
128
+                    $this->addError( $path, 'Invalid IP address', 'format', array( 'format' => $schema->format ) );
129 129
                 }
130 130
                 break;
131 131
 
132 132
             case 'ipv6':
133
-                if (null === filter_var($element, FILTER_VALIDATE_IP, FILTER_NULL_ON_FAILURE | FILTER_FLAG_IPV6)) {
134
-                    $this->addError($path, 'Invalid IP address', 'format', array('format' => $schema->format));
133
+                if ( null === filter_var( $element, FILTER_VALIDATE_IP, FILTER_NULL_ON_FAILURE | FILTER_FLAG_IPV6 ) ) {
134
+                    $this->addError( $path, 'Invalid IP address', 'format', array( 'format' => $schema->format ) );
135 135
                 }
136 136
                 break;
137 137
 
138 138
             case 'host-name':
139 139
             case 'hostname':
140
-                if (!$this->validateHostname($element)) {
141
-                    $this->addError($path, 'Invalid hostname', 'format', array('format' => $schema->format));
140
+                if ( ! $this->validateHostname( $element ) ) {
141
+                    $this->addError( $path, 'Invalid hostname', 'format', array( 'format' => $schema->format ) );
142 142
                 }
143 143
                 break;
144 144
 
@@ -153,15 +153,15 @@  discard block
 block discarded – undo
153 153
         }
154 154
     }
155 155
 
156
-    protected function validateDateTime($datetime, $format)
156
+    protected function validateDateTime( $datetime, $format )
157 157
     {
158
-        $dt = \DateTime::createFromFormat($format, $datetime);
158
+        $dt = \DateTime::createFromFormat( $format, $datetime );
159 159
 
160
-        if (!$dt) {
160
+        if ( ! $dt ) {
161 161
             return false;
162 162
         }
163 163
 
164
-        if ($datetime === $dt->format($format)) {
164
+        if ( $datetime === $dt->format( $format ) ) {
165 165
             return true;
166 166
         }
167 167
 
@@ -169,46 +169,46 @@  discard block
 block discarded – undo
169 169
         // which will fail the above string comparison because the passed
170 170
         // $datetime may be '2000-05-01T12:12:12.123Z' but format() will return
171 171
         // '2000-05-01T12:12:12.123000Z'
172
-        if ((strpos('u', $format) !== -1) && (preg_match('/\.\d+Z$/', $datetime))) {
172
+        if ( ( strpos( 'u', $format ) !== -1 ) && ( preg_match( '/\.\d+Z$/', $datetime ) ) ) {
173 173
             return true;
174 174
         }
175 175
 
176 176
         return false;
177 177
     }
178 178
 
179
-    protected function validateRegex($regex)
179
+    protected function validateRegex( $regex )
180 180
     {
181
-        return false !== @preg_match('/' . $regex . '/u', '');
181
+        return false !== @preg_match( '/' . $regex . '/u', '' );
182 182
     }
183 183
 
184
-    protected function validateColor($color)
184
+    protected function validateColor( $color )
185 185
     {
186
-        if (in_array(strtolower($color), array('aqua', 'black', 'blue', 'fuchsia',
186
+        if ( in_array( strtolower( $color ), array( 'aqua', 'black', 'blue', 'fuchsia',
187 187
             'gray', 'green', 'lime', 'maroon', 'navy', 'olive', 'orange', 'purple',
188
-            'red', 'silver', 'teal', 'white', 'yellow'))) {
188
+            'red', 'silver', 'teal', 'white', 'yellow' ) ) ) {
189 189
             return true;
190 190
         }
191 191
 
192
-        return preg_match('/^#([a-f0-9]{3}|[a-f0-9]{6})$/i', $color);
192
+        return preg_match( '/^#([a-f0-9]{3}|[a-f0-9]{6})$/i', $color );
193 193
     }
194 194
 
195
-    protected function validateStyle($style)
195
+    protected function validateStyle( $style )
196 196
     {
197
-        $properties     = explode(';', rtrim($style, ';'));
198
-        $invalidEntries = preg_grep('/^\s*[-a-z]+\s*:\s*.+$/i', $properties, PREG_GREP_INVERT);
197
+        $properties     = explode( ';', rtrim( $style, ';' ) );
198
+        $invalidEntries = preg_grep( '/^\s*[-a-z]+\s*:\s*.+$/i', $properties, PREG_GREP_INVERT );
199 199
 
200
-        return empty($invalidEntries);
200
+        return empty( $invalidEntries );
201 201
     }
202 202
 
203
-    protected function validatePhone($phone)
203
+    protected function validatePhone( $phone )
204 204
     {
205
-        return preg_match('/^\+?(\(\d{3}\)|\d{3}) \d{3} \d{4}$/', $phone);
205
+        return preg_match( '/^\+?(\(\d{3}\)|\d{3}) \d{3} \d{4}$/', $phone );
206 206
     }
207 207
 
208
-    protected function validateHostname($host)
208
+    protected function validateHostname( $host )
209 209
     {
210 210
         $hostnameRegex = '/^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])$/i';
211 211
 
212
-        return preg_match($hostnameRegex, $host);
212
+        return preg_match( $hostnameRegex, $host );
213 213
     }
214 214
 }
Please login to merge, or discard this patch.
justinrainbow/json-schema/src/JsonSchema/Constraints/StringConstraint.php 1 patch
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -22,39 +22,39 @@
 block discarded – undo
22 22
     /**
23 23
      * {@inheritdoc}
24 24
      */
25
-    public function check(&$element, $schema = null, JsonPointer $path = null, $i = null)
25
+    public function check( &$element, $schema = null, JsonPointer $path = null, $i = null )
26 26
     {
27 27
         // Verify maxLength
28
-        if (isset($schema->maxLength) && $this->strlen($element) > $schema->maxLength) {
29
-            $this->addError($path, 'Must be at most ' . $schema->maxLength . ' characters long', 'maxLength', array(
28
+        if ( isset( $schema->maxLength ) && $this->strlen( $element ) > $schema->maxLength ) {
29
+            $this->addError( $path, 'Must be at most ' . $schema->maxLength . ' characters long', 'maxLength', array(
30 30
                 'maxLength' => $schema->maxLength,
31
-            ));
31
+            ) );
32 32
         }
33 33
 
34 34
         //verify minLength
35
-        if (isset($schema->minLength) && $this->strlen($element) < $schema->minLength) {
36
-            $this->addError($path, 'Must be at least ' . $schema->minLength . ' characters long', 'minLength', array(
35
+        if ( isset( $schema->minLength ) && $this->strlen( $element ) < $schema->minLength ) {
36
+            $this->addError( $path, 'Must be at least ' . $schema->minLength . ' characters long', 'minLength', array(
37 37
                 'minLength' => $schema->minLength,
38
-            ));
38
+            ) );
39 39
         }
40 40
 
41 41
         // Verify a regex pattern
42
-        if (isset($schema->pattern) && !preg_match('#' . str_replace('#', '\\#', $schema->pattern) . '#u', $element)) {
43
-            $this->addError($path, 'Does not match the regex pattern ' . $schema->pattern, 'pattern', array(
42
+        if ( isset( $schema->pattern ) && ! preg_match( '#' . str_replace( '#', '\\#', $schema->pattern ) . '#u', $element ) ) {
43
+            $this->addError( $path, 'Does not match the regex pattern ' . $schema->pattern, 'pattern', array(
44 44
                 'pattern' => $schema->pattern,
45
-            ));
45
+            ) );
46 46
         }
47 47
 
48
-        $this->checkFormat($element, $schema, $path, $i);
48
+        $this->checkFormat( $element, $schema, $path, $i );
49 49
     }
50 50
 
51
-    private function strlen($string)
51
+    private function strlen( $string )
52 52
     {
53
-        if (extension_loaded('mbstring')) {
54
-            return mb_strlen($string, mb_detect_encoding($string));
53
+        if ( extension_loaded( 'mbstring' ) ) {
54
+            return mb_strlen( $string, mb_detect_encoding( $string ) );
55 55
         }
56 56
 
57 57
         // mbstring is present on all test platforms, so strlen() can be ignored for coverage
58
-        return strlen($string); // @codeCoverageIgnore
58
+        return strlen( $string ); // @codeCoverageIgnore
59 59
     }
60 60
 }
Please login to merge, or discard this patch.
justinrainbow/json-schema/src/JsonSchema/Constraints/SchemaConstraint.php 1 patch
Spacing   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -28,67 +28,67 @@
 block discarded – undo
28 28
     /**
29 29
      * {@inheritdoc}
30 30
      */
31
-    public function check(&$element, $schema = null, JsonPointer $path = null, $i = null)
31
+    public function check( &$element, $schema = null, JsonPointer $path = null, $i = null )
32 32
     {
33
-        if ($schema !== null) {
33
+        if ( $schema !== null ) {
34 34
             // passed schema
35 35
             $validationSchema = $schema;
36
-        } elseif ($this->getTypeCheck()->propertyExists($element, $this->inlineSchemaProperty)) {
36
+        } elseif ( $this->getTypeCheck()->propertyExists( $element, $this->inlineSchemaProperty ) ) {
37 37
             // inline schema
38
-            $validationSchema = $this->getTypeCheck()->propertyGet($element, $this->inlineSchemaProperty);
38
+            $validationSchema = $this->getTypeCheck()->propertyGet( $element, $this->inlineSchemaProperty );
39 39
         } else {
40
-            throw new InvalidArgumentException('no schema found to verify against');
40
+            throw new InvalidArgumentException( 'no schema found to verify against' );
41 41
         }
42 42
 
43 43
         // cast array schemas to object
44
-        if (is_array($validationSchema)) {
45
-            $validationSchema = BaseConstraint::arrayToObjectRecursive($validationSchema);
44
+        if ( is_array( $validationSchema ) ) {
45
+            $validationSchema = BaseConstraint::arrayToObjectRecursive( $validationSchema );
46 46
         }
47 47
 
48 48
         // validate schema against whatever is defined in $validationSchema->$schema. If no
49 49
         // schema is defined, assume self::DEFAULT_SCHEMA_SPEC (currently draft-04).
50
-        if ($this->factory->getConfig(self::CHECK_MODE_VALIDATE_SCHEMA)) {
51
-            if (!$this->getTypeCheck()->isObject($validationSchema)) {
52
-                throw new RuntimeException('Cannot validate the schema of a non-object');
50
+        if ( $this->factory->getConfig( self::CHECK_MODE_VALIDATE_SCHEMA ) ) {
51
+            if ( ! $this->getTypeCheck()->isObject( $validationSchema ) ) {
52
+                throw new RuntimeException( 'Cannot validate the schema of a non-object' );
53 53
             }
54
-            if ($this->getTypeCheck()->propertyExists($validationSchema, '$schema')) {
55
-                $schemaSpec = $this->getTypeCheck()->propertyGet($validationSchema, '$schema');
54
+            if ( $this->getTypeCheck()->propertyExists( $validationSchema, '$schema' ) ) {
55
+                $schemaSpec = $this->getTypeCheck()->propertyGet( $validationSchema, '$schema' );
56 56
             } else {
57 57
                 $schemaSpec = self::DEFAULT_SCHEMA_SPEC;
58 58
             }
59 59
 
60 60
             // get the spec schema
61 61
             $schemaStorage = $this->factory->getSchemaStorage();
62
-            if (!$this->getTypeCheck()->isObject($schemaSpec)) {
63
-                $schemaSpec = $schemaStorage->getSchema($schemaSpec);
62
+            if ( ! $this->getTypeCheck()->isObject( $schemaSpec ) ) {
63
+                $schemaSpec = $schemaStorage->getSchema( $schemaSpec );
64 64
             }
65 65
 
66 66
             // save error count, config & subtract CHECK_MODE_VALIDATE_SCHEMA
67 67
             $initialErrorCount = $this->numErrors();
68 68
             $initialConfig = $this->factory->getConfig();
69 69
             $initialContext = $this->factory->getErrorContext();
70
-            $this->factory->removeConfig(self::CHECK_MODE_VALIDATE_SCHEMA | self::CHECK_MODE_APPLY_DEFAULTS);
71
-            $this->factory->addConfig(self::CHECK_MODE_TYPE_CAST);
72
-            $this->factory->setErrorContext(Validator::ERROR_SCHEMA_VALIDATION);
70
+            $this->factory->removeConfig( self::CHECK_MODE_VALIDATE_SCHEMA | self::CHECK_MODE_APPLY_DEFAULTS );
71
+            $this->factory->addConfig( self::CHECK_MODE_TYPE_CAST );
72
+            $this->factory->setErrorContext( Validator::ERROR_SCHEMA_VALIDATION );
73 73
 
74 74
             // validate schema
75 75
             try {
76
-                $this->check($validationSchema, $schemaSpec);
77
-            } catch (\Exception $e) {
78
-                if ($this->factory->getConfig(self::CHECK_MODE_EXCEPTIONS)) {
79
-                    throw new InvalidSchemaException('Schema did not pass validation', 0, $e);
76
+                $this->check( $validationSchema, $schemaSpec );
77
+            } catch ( \Exception $e ) {
78
+                if ( $this->factory->getConfig( self::CHECK_MODE_EXCEPTIONS ) ) {
79
+                    throw new InvalidSchemaException( 'Schema did not pass validation', 0, $e );
80 80
                 }
81 81
             }
82
-            if ($this->numErrors() > $initialErrorCount) {
83
-                $this->addError($path, 'Schema is not valid', 'schema');
82
+            if ( $this->numErrors() > $initialErrorCount ) {
83
+                $this->addError( $path, 'Schema is not valid', 'schema' );
84 84
             }
85 85
 
86 86
             // restore the initial config
87
-            $this->factory->setConfig($initialConfig);
88
-            $this->factory->setErrorContext($initialContext);
87
+            $this->factory->setConfig( $initialConfig );
88
+            $this->factory->setErrorContext( $initialContext );
89 89
         }
90 90
 
91 91
         // validate element against $validationSchema
92
-        $this->checkUndefined($element, $validationSchema, $path, $i);
92
+        $this->checkUndefined( $element, $validationSchema, $path, $i );
93 93
     }
94 94
 }
Please login to merge, or discard this patch.
justinrainbow/json-schema/src/JsonSchema/Constraints/ObjectConstraint.php 1 patch
Spacing   +54 added lines, -54 removed lines patch added patch discarded remove patch
@@ -27,52 +27,52 @@  discard block
 block discarded – undo
27 27
     /**
28 28
      * {@inheritdoc}
29 29
      */
30
-    public function check(&$element, $schema = null, JsonPointer $path = null, $properties = null,
31
-        $additionalProp = null, $patternProperties = null, $appliedDefaults = array())
30
+    public function check( &$element, $schema = null, JsonPointer $path = null, $properties = null,
31
+        $additionalProp = null, $patternProperties = null, $appliedDefaults = array() )
32 32
     {
33
-        if ($element instanceof UndefinedConstraint) {
33
+        if ( $element instanceof UndefinedConstraint ) {
34 34
             return;
35 35
         }
36 36
 
37 37
         $this->appliedDefaults = $appliedDefaults;
38 38
 
39 39
         $matches = array();
40
-        if ($patternProperties) {
40
+        if ( $patternProperties ) {
41 41
             // validate the element pattern properties
42
-            $matches = $this->validatePatternProperties($element, $path, $patternProperties);
42
+            $matches = $this->validatePatternProperties( $element, $path, $patternProperties );
43 43
         }
44 44
 
45
-        if ($properties) {
45
+        if ( $properties ) {
46 46
             // validate the element properties
47
-            $this->validateProperties($element, $properties, $path);
47
+            $this->validateProperties( $element, $properties, $path );
48 48
         }
49 49
 
50 50
         // validate additional element properties & constraints
51
-        $this->validateElement($element, $matches, $schema, $path, $properties, $additionalProp);
51
+        $this->validateElement( $element, $matches, $schema, $path, $properties, $additionalProp );
52 52
     }
53 53
 
54
-    public function validatePatternProperties($element, JsonPointer $path = null, $patternProperties)
54
+    public function validatePatternProperties( $element, JsonPointer $path = null, $patternProperties )
55 55
     {
56
-        $try = array('/', '#', '+', '~', '%');
56
+        $try = array( '/', '#', '+', '~', '%' );
57 57
         $matches = array();
58
-        foreach ($patternProperties as $pregex => $schema) {
58
+        foreach ( $patternProperties as $pregex => $schema ) {
59 59
             $delimiter = '/';
60 60
             // Choose delimiter. Necessary for patterns like ^/ , otherwise you get error
61
-            foreach ($try as $delimiter) {
62
-                if (strpos($pregex, $delimiter) === false) { // safe to use
61
+            foreach ( $try as $delimiter ) {
62
+                if ( strpos( $pregex, $delimiter ) === false ) { // safe to use
63 63
                     break;
64 64
                 }
65 65
             }
66 66
 
67 67
             // Validate the pattern before using it to test for matches
68
-            if (@preg_match($delimiter . $pregex . $delimiter . 'u', '') === false) {
69
-                $this->addError($path, 'The pattern "' . $pregex . '" is invalid', 'pregex', array('pregex' => $pregex));
68
+            if ( @preg_match( $delimiter . $pregex . $delimiter . 'u', '' ) === false ) {
69
+                $this->addError( $path, 'The pattern "' . $pregex . '" is invalid', 'pregex', array( 'pregex' => $pregex ) );
70 70
                 continue;
71 71
             }
72
-            foreach ($element as $i => $value) {
73
-                if (preg_match($delimiter . $pregex . $delimiter . 'u', $i)) {
74
-                    $matches[] = $i;
75
-                    $this->checkUndefined($value, $schema ?: new \stdClass(), $path, $i, in_array($i, $this->appliedDefaults));
72
+            foreach ( $element as $i => $value ) {
73
+                if ( preg_match( $delimiter . $pregex . $delimiter . 'u', $i ) ) {
74
+                    $matches[ ] = $i;
75
+                    $this->checkUndefined( $value, $schema ?: new \stdClass(), $path, $i, in_array( $i, $this->appliedDefaults ) );
76 76
                 }
77 77
             }
78 78
         }
@@ -90,37 +90,37 @@  discard block
 block discarded – undo
90 90
      * @param \StdClass        $properties     Properties
91 91
      * @param mixed            $additionalProp Additional properties
92 92
      */
93
-    public function validateElement($element, $matches, $schema = null, JsonPointer $path = null,
94
-        $properties = null, $additionalProp = null)
93
+    public function validateElement( $element, $matches, $schema = null, JsonPointer $path = null,
94
+        $properties = null, $additionalProp = null )
95 95
     {
96
-        $this->validateMinMaxConstraint($element, $schema, $path);
96
+        $this->validateMinMaxConstraint( $element, $schema, $path );
97 97
 
98
-        foreach ($element as $i => $value) {
99
-            $definition = $this->getProperty($properties, $i);
98
+        foreach ( $element as $i => $value ) {
99
+            $definition = $this->getProperty( $properties, $i );
100 100
 
101 101
             // no additional properties allowed
102
-            if (!in_array($i, $matches) && $additionalProp === false && $this->inlineSchemaProperty !== $i && !$definition) {
103
-                $this->addError($path, 'The property ' . $i . ' is not defined and the definition does not allow additional properties', 'additionalProp');
102
+            if ( ! in_array( $i, $matches ) && $additionalProp === false && $this->inlineSchemaProperty !== $i && ! $definition ) {
103
+                $this->addError( $path, 'The property ' . $i . ' is not defined and the definition does not allow additional properties', 'additionalProp' );
104 104
             }
105 105
 
106 106
             // additional properties defined
107
-            if (!in_array($i, $matches) && $additionalProp && !$definition) {
108
-                if ($additionalProp === true) {
109
-                    $this->checkUndefined($value, null, $path, $i, in_array($i, $this->appliedDefaults));
107
+            if ( ! in_array( $i, $matches ) && $additionalProp && ! $definition ) {
108
+                if ( $additionalProp === true ) {
109
+                    $this->checkUndefined( $value, null, $path, $i, in_array( $i, $this->appliedDefaults ) );
110 110
                 } else {
111
-                    $this->checkUndefined($value, $additionalProp, $path, $i, in_array($i, $this->appliedDefaults));
111
+                    $this->checkUndefined( $value, $additionalProp, $path, $i, in_array( $i, $this->appliedDefaults ) );
112 112
                 }
113 113
             }
114 114
 
115 115
             // property requires presence of another
116
-            $require = $this->getProperty($definition, 'requires');
117
-            if ($require && !$this->getProperty($element, $require)) {
118
-                $this->addError($path, 'The presence of the property ' . $i . ' requires that ' . $require . ' also be present', 'requires');
116
+            $require = $this->getProperty( $definition, 'requires' );
117
+            if ( $require && ! $this->getProperty( $element, $require ) ) {
118
+                $this->addError( $path, 'The presence of the property ' . $i . ' requires that ' . $require . ' also be present', 'requires' );
119 119
             }
120 120
 
121
-            $property = $this->getProperty($element, $i, $this->factory->createInstanceFor('undefined'));
122
-            if (is_object($property)) {
123
-                $this->validateMinMaxConstraint(!($property instanceof UndefinedConstraint) ? $property : $element, $definition, $path);
121
+            $property = $this->getProperty( $element, $i, $this->factory->createInstanceFor( 'undefined' ) );
122
+            if ( is_object( $property ) ) {
123
+                $this->validateMinMaxConstraint( ! ( $property instanceof UndefinedConstraint ) ? $property : $element, $definition, $path );
124 124
             }
125 125
         }
126 126
     }
@@ -132,17 +132,17 @@  discard block
 block discarded – undo
132 132
      * @param \stdClass        $properties Property definitions
133 133
      * @param JsonPointer|null $path       Path?
134 134
      */
135
-    public function validateProperties(&$element, $properties = null, JsonPointer $path = null)
135
+    public function validateProperties( &$element, $properties = null, JsonPointer $path = null )
136 136
     {
137
-        $undefinedConstraint = $this->factory->createInstanceFor('undefined');
137
+        $undefinedConstraint = $this->factory->createInstanceFor( 'undefined' );
138 138
 
139
-        foreach ($properties as $i => $value) {
140
-            $property = &$this->getProperty($element, $i, $undefinedConstraint);
141
-            $definition = $this->getProperty($properties, $i);
139
+        foreach ( $properties as $i => $value ) {
140
+            $property = &$this->getProperty( $element, $i, $undefinedConstraint );
141
+            $definition = $this->getProperty( $properties, $i );
142 142
 
143
-            if (is_object($definition)) {
143
+            if ( is_object( $definition ) ) {
144 144
                 // Undefined constraint will check for is_object() and quit if is not - so why pass it?
145
-                $this->checkUndefined($property, $definition, $path, $i, in_array($i, $this->appliedDefaults));
145
+                $this->checkUndefined( $property, $definition, $path, $i, in_array( $i, $this->appliedDefaults ) );
146 146
             }
147 147
         }
148 148
     }
@@ -156,11 +156,11 @@  discard block
 block discarded – undo
156 156
      *
157 157
      * @return mixed
158 158
      */
159
-    protected function &getProperty(&$element, $property, $fallback = null)
159
+    protected function &getProperty( &$element, $property, $fallback = null )
160 160
     {
161
-        if (is_array($element) && (isset($element[$property]) || array_key_exists($property, $element)) /*$this->checkMode == self::CHECK_MODE_TYPE_CAST*/) {
162
-            return $element[$property];
163
-        } elseif (is_object($element) && property_exists($element, $property)) {
161
+        if ( is_array( $element ) && ( isset( $element[ $property ] ) || array_key_exists( $property, $element ) ) /*$this->checkMode == self::CHECK_MODE_TYPE_CAST*/ ) {
162
+            return $element[ $property ];
163
+        } elseif ( is_object( $element ) && property_exists( $element, $property ) ) {
164 164
             return $element->$property;
165 165
         }
166 166
 
@@ -174,18 +174,18 @@  discard block
 block discarded – undo
174 174
      * @param \stdClass        $objectDefinition ObjectConstraint definition
175 175
      * @param JsonPointer|null $path             Path to test?
176 176
      */
177
-    protected function validateMinMaxConstraint($element, $objectDefinition, JsonPointer $path = null)
177
+    protected function validateMinMaxConstraint( $element, $objectDefinition, JsonPointer $path = null )
178 178
     {
179 179
         // Verify minimum number of properties
180
-        if (isset($objectDefinition->minProperties) && !is_object($objectDefinition->minProperties)) {
181
-            if ($this->getTypeCheck()->propertyCount($element) < $objectDefinition->minProperties) {
182
-                $this->addError($path, 'Must contain a minimum of ' . $objectDefinition->minProperties . ' properties', 'minProperties', array('minProperties' => $objectDefinition->minProperties));
180
+        if ( isset( $objectDefinition->minProperties ) && ! is_object( $objectDefinition->minProperties ) ) {
181
+            if ( $this->getTypeCheck()->propertyCount( $element ) < $objectDefinition->minProperties ) {
182
+                $this->addError( $path, 'Must contain a minimum of ' . $objectDefinition->minProperties . ' properties', 'minProperties', array( 'minProperties' => $objectDefinition->minProperties ) );
183 183
             }
184 184
         }
185 185
         // Verify maximum number of properties
186
-        if (isset($objectDefinition->maxProperties) && !is_object($objectDefinition->maxProperties)) {
187
-            if ($this->getTypeCheck()->propertyCount($element) > $objectDefinition->maxProperties) {
188
-                $this->addError($path, 'Must contain no more than ' . $objectDefinition->maxProperties . ' properties', 'maxProperties', array('maxProperties' => $objectDefinition->maxProperties));
186
+        if ( isset( $objectDefinition->maxProperties ) && ! is_object( $objectDefinition->maxProperties ) ) {
187
+            if ( $this->getTypeCheck()->propertyCount( $element ) > $objectDefinition->maxProperties ) {
188
+                $this->addError( $path, 'Must contain no more than ' . $objectDefinition->maxProperties . ' properties', 'maxProperties', array( 'maxProperties' => $objectDefinition->maxProperties ) );
189 189
             }
190 190
         }
191 191
     }
Please login to merge, or discard this patch.