Completed
Pull Request — master (#925)
by Asmir
02:40
created
src/XmlDeserializationVisitor.php 1 patch
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -63,7 +63,7 @@  discard block
 block discarded – undo
63 63
 
64 64
         if (false !== stripos($data, '<!doctype')) {
65 65
             $internalSubset = $this->getDomDocumentTypeEntitySubset($data);
66
-            if (!in_array($internalSubset, $this->doctypeWhitelist, true)) {
66
+            if ( ! in_array($internalSubset, $this->doctypeWhitelist, true)) {
67 67
                 throw new InvalidArgumentException(sprintf(
68 68
                     'The document type "%s" is not allowed. If it is safe, you may add it to the whitelist configuration.',
69 69
                     $internalSubset
@@ -85,7 +85,7 @@  discard block
 block discarded – undo
85 85
 
86 86
     private function emptyStringToSpaceCharacter($data)
87 87
     {
88
-        return $data === '' ? ' ' : (string)$data;
88
+        return $data === '' ? ' ' : (string) $data;
89 89
     }
90 90
 
91 91
     public function visitNull($data, array $type): void
@@ -95,12 +95,12 @@  discard block
 block discarded – undo
95 95
 
96 96
     public function visitString($data, array $type): string
97 97
     {
98
-        return (string)$data;
98
+        return (string) $data;
99 99
     }
100 100
 
101 101
     public function visitBoolean($data, array $type): bool
102 102
     {
103
-        $data = (string)$data;
103
+        $data = (string) $data;
104 104
 
105 105
         if ('true' === $data || '1' === $data) {
106 106
             return true;
@@ -113,12 +113,12 @@  discard block
 block discarded – undo
113 113
 
114 114
     public function visitInteger($data, array $type): int
115 115
     {
116
-        return (integer)$data;
116
+        return (integer) $data;
117 117
     }
118 118
 
119 119
     public function visitDouble($data, array $type): float
120 120
     {
121
-        return (double)$data;
121
+        return (double) $data;
122 122
     }
123 123
 
124 124
     public function visitArray($data, array $type): array
@@ -163,7 +163,7 @@  discard block
 block discarded – undo
163 163
             $nodes = $data->xpath($entryName);
164 164
         }
165 165
 
166
-        if (!\count($nodes)) {
166
+        if ( ! \count($nodes)) {
167 167
             return array();
168 168
         }
169 169
 
@@ -191,7 +191,7 @@  discard block
 block discarded – undo
191 191
                 $nodes = $data->children($namespace)->$entryName;
192 192
                 foreach ($nodes as $v) {
193 193
                     $attrs = $v->attributes();
194
-                    if (!isset($attrs[$this->currentMetadata->xmlKeyAttribute])) {
194
+                    if ( ! isset($attrs[$this->currentMetadata->xmlKeyAttribute])) {
195 195
                         throw new RuntimeException(sprintf('The key attribute "%s" must be set for each entry of the map.', $this->currentMetadata->xmlKeyAttribute));
196 196
                     }
197 197
 
@@ -211,15 +211,15 @@  discard block
 block discarded – undo
211 211
         switch (true) {
212 212
             // Check XML attribute for discriminatorFieldName
213 213
             case $metadata->xmlDiscriminatorAttribute && isset($data[$metadata->discriminatorFieldName]):
214
-                return (string)$data[$metadata->discriminatorFieldName];
214
+                return (string) $data[$metadata->discriminatorFieldName];
215 215
 
216 216
             // Check XML element with namespace for discriminatorFieldName
217
-            case !$metadata->xmlDiscriminatorAttribute && null !== $metadata->xmlDiscriminatorNamespace && isset($data->children($metadata->xmlDiscriminatorNamespace)->{$metadata->discriminatorFieldName}):
218
-                return (string)$data->children($metadata->xmlDiscriminatorNamespace)->{$metadata->discriminatorFieldName};
217
+            case ! $metadata->xmlDiscriminatorAttribute && null !== $metadata->xmlDiscriminatorNamespace && isset($data->children($metadata->xmlDiscriminatorNamespace)->{$metadata->discriminatorFieldName}):
218
+                return (string) $data->children($metadata->xmlDiscriminatorNamespace)->{$metadata->discriminatorFieldName};
219 219
 
220 220
             // Check XML element for discriminatorFieldName
221 221
             case isset($data->{$metadata->discriminatorFieldName}):
222
-                return (string)$data->{$metadata->discriminatorFieldName};
222
+                return (string) $data->{$metadata->discriminatorFieldName};
223 223
 
224 224
             default:
225 225
                 throw new LogicException(sprintf(
@@ -240,7 +240,7 @@  discard block
 block discarded – undo
240 240
     {
241 241
         $name = $metadata->serializedName;
242 242
 
243
-        if (!$metadata->type) {
243
+        if ( ! $metadata->type) {
244 244
             throw new RuntimeException(sprintf('You must define a type for %s::$%s.', $metadata->reflection->class, $metadata->name));
245 245
         }
246 246
 
@@ -260,7 +260,7 @@  discard block
 block discarded – undo
260 260
 
261 261
         if ($metadata->xmlCollection) {
262 262
             $enclosingElem = $data;
263
-            if (!$metadata->xmlCollectionInline) {
263
+            if ( ! $metadata->xmlCollectionInline) {
264 264
                 $enclosingElem = $data->children($metadata->xmlNamespace)->$name;
265 265
             }
266 266
 
@@ -272,7 +272,7 @@  discard block
 block discarded – undo
272 272
 
273 273
         if ($metadata->xmlNamespace) {
274 274
             $node = $data->children($metadata->xmlNamespace)->$name;
275
-            if (!$node->count()) {
275
+            if ( ! $node->count()) {
276 276
                 throw new NotAcceptableException();
277 277
             }
278 278
         } else {
@@ -282,9 +282,9 @@  discard block
 block discarded – undo
282 282
             if (isset($namespaces[''])) {
283 283
                 $prefix = uniqid('ns-');
284 284
                 $data->registerXPathNamespace($prefix, $namespaces['']);
285
-                $nodes = $data->xpath('./' . $prefix . ':' . $name);
285
+                $nodes = $data->xpath('./'.$prefix.':'.$name);
286 286
             } else {
287
-                $nodes = $data->xpath('./' . $name);
287
+                $nodes = $data->xpath('./'.$name);
288 288
             }
289 289
             if (empty($nodes)) {
290 290
                 throw new NotAcceptableException();
@@ -397,7 +397,7 @@  discard block
 block discarded – undo
397 397
 
398 398
             $xsiAttributes = $value->attributes('http://www.w3.org/2001/XMLSchema-instance');
399 399
             if (isset($xsiAttributes['nil'])
400
-                && ((string)$xsiAttributes['nil'] === 'true' || (string)$xsiAttributes['nil'] === '1')
400
+                && ((string) $xsiAttributes['nil'] === 'true' || (string) $xsiAttributes['nil'] === '1')
401 401
             ) {
402 402
                 return true;
403 403
             }
Please login to merge, or discard this patch.
src/SerializationGraphNavigator.php 2 patches
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -68,8 +68,7 @@
 block discarded – undo
68 68
         AccessorStrategyInterface $accessor,
69 69
         EventDispatcherInterface $dispatcher = null,
70 70
         ExpressionEvaluatorInterface $expressionEvaluator = null
71
-    )
72
-    {
71
+    ) {
73 72
         $this->dispatcher = $dispatcher ?: new EventDispatcher();
74 73
         $this->metadataFactory = $metadataFactory;
75 74
         $this->handlerRegistry = $handlerRegistry;
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -130,33 +130,33 @@
 block discarded – undo
130 130
 
131 131
         switch ($type['name']) {
132 132
             case 'NULL':
133
-                if (!$this->shouldSerializeNull) {
133
+                if ( ! $this->shouldSerializeNull) {
134 134
                     throw new NotAcceptableException();
135 135
                 }
136 136
                 return $this->visitor->visitNull($data, $type);
137 137
 
138 138
             case 'string':
139
-                return $this->visitor->visitString((string)$data, $type);
139
+                return $this->visitor->visitString((string) $data, $type);
140 140
 
141 141
             case 'int':
142 142
             case 'integer':
143
-                return $this->visitor->visitInteger((int)$data, $type);
143
+                return $this->visitor->visitInteger((int) $data, $type);
144 144
 
145 145
             case 'bool':
146 146
             case 'boolean':
147
-                return $this->visitor->visitBoolean((bool)$data, $type);
147
+                return $this->visitor->visitBoolean((bool) $data, $type);
148 148
 
149 149
             case 'double':
150 150
             case 'float':
151
-                return $this->visitor->visitDouble((float)$data, $type);
151
+                return $this->visitor->visitDouble((float) $data, $type);
152 152
 
153 153
             case 'array':
154
-                return $this->visitor->visitArray((array)$data, $type);
154
+                return $this->visitor->visitArray((array) $data, $type);
155 155
 
156 156
             case 'resource':
157 157
                 $msg = 'Resources are not supported in serialized data.';
158 158
                 if (null !== $path = $this->context->getPath()) {
159
-                    $msg .= ' Path: ' . $path;
159
+                    $msg .= ' Path: '.$path;
160 160
                 }
161 161
 
162 162
                 throw new RuntimeException($msg);
Please login to merge, or discard this patch.
src/XmlSerializationVisitor.php 1 patch
Spacing   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -78,7 +78,7 @@  discard block
 block discarded – undo
78 78
 
79 79
     public function createRoot(ClassMetadata $metadata = null, $rootName = null, $rootNamespace = null)
80 80
     {
81
-        if ($metadata !== null && !empty($metadata->xmlRootName)) {
81
+        if ($metadata !== null && ! empty($metadata->xmlRootName)) {
82 82
             $rootName = $metadata->xmlRootName;
83 83
             $rootNamespace = $metadata->xmlRootNamespace ?: $this->getClassDefaultNamespace($metadata);
84 84
         } else {
@@ -111,12 +111,12 @@  discard block
 block discarded – undo
111 111
     {
112 112
         $doCData = null !== $this->currentMetadata ? $this->currentMetadata->xmlElementCData : true;
113 113
 
114
-        return $doCData ? $this->document->createCDATASection($data) : $this->document->createTextNode((string)$data);
114
+        return $doCData ? $this->document->createCDATASection($data) : $this->document->createTextNode((string) $data);
115 115
     }
116 116
 
117 117
     public function visitSimpleString($data, array $type)
118 118
     {
119
-        return $this->document->createTextNode((string)$data);
119
+        return $this->document->createTextNode((string) $data);
120 120
     }
121 121
 
122 122
     public function visitBoolean(bool $data, array $type)
@@ -126,7 +126,7 @@  discard block
 block discarded – undo
126 126
 
127 127
     public function visitInteger(int $data, array $type)
128 128
     {
129
-        return $this->document->createTextNode((string)$data);
129
+        return $this->document->createTextNode((string) $data);
130 130
     }
131 131
 
132 132
     public function visitDouble(float $data, array $type)
@@ -134,7 +134,7 @@  discard block
 block discarded – undo
134 134
         if (floor($data) === $data) {
135 135
             return $this->document->createTextNode($data.".0");
136 136
         } else {
137
-            return $this->document->createTextNode((string)$data);
137
+            return $this->document->createTextNode((string) $data);
138 138
         }
139 139
     }
140 140
 
@@ -151,14 +151,14 @@  discard block
 block discarded – undo
151 151
         $elType = $this->getElementType($type);
152 152
         foreach ($data as $k => $v) {
153 153
 
154
-            $tagName = (null !== $this->currentMetadata && $this->currentMetadata->xmlKeyValuePairs && $this->isElementNameValid((string)$k)) ? $k : $entryName;
154
+            $tagName = (null !== $this->currentMetadata && $this->currentMetadata->xmlKeyValuePairs && $this->isElementNameValid((string) $k)) ? $k : $entryName;
155 155
 
156 156
             $entryNode = $this->createElement($tagName, $namespace);
157 157
             $this->currentNode->appendChild($entryNode);
158 158
             $this->setCurrentNode($entryNode);
159 159
 
160 160
             if (null !== $keyAttributeName) {
161
-                $entryNode->setAttribute($keyAttributeName, (string)$k);
161
+                $entryNode->setAttribute($keyAttributeName, (string) $k);
162 162
             }
163 163
 
164 164
             try {
@@ -193,7 +193,7 @@  discard block
 block discarded – undo
193 193
             $node = $this->navigator->accept($v, $metadata->type);
194 194
             $this->revertCurrentMetadata();
195 195
 
196
-            if (!$node instanceof \DOMCharacterData) {
196
+            if ( ! $node instanceof \DOMCharacterData) {
197 197
                 throw new RuntimeException(sprintf('Unsupported value for XML attribute for %s. Expected character data, but got %s.', $metadata->name, json_encode($v)));
198 198
             }
199 199
 
@@ -203,7 +203,7 @@  discard block
 block discarded – undo
203 203
         }
204 204
 
205 205
         if (($metadata->xmlValue && $this->currentNode->childNodes->length > 0)
206
-            || (!$metadata->xmlValue && $this->hasValue)
206
+            || ( ! $metadata->xmlValue && $this->hasValue)
207 207
         ) {
208 208
             throw new RuntimeException(sprintf('If you make use of @XmlValue, all other properties in the class must have the @XmlAttribute annotation. Invalid usage detected in class %s.', $metadata->class));
209 209
         }
@@ -215,7 +215,7 @@  discard block
 block discarded – undo
215 215
             $node = $this->navigator->accept($v, $metadata->type);
216 216
             $this->revertCurrentMetadata();
217 217
 
218
-            if (!$node instanceof \DOMCharacterData) {
218
+            if ( ! $node instanceof \DOMCharacterData) {
219 219
                 throw new RuntimeException(sprintf('Unsupported value for property %s::$%s. Expected character data, but got %s.', $metadata->reflection->class, $metadata->reflection->name, \is_object($node) ? \get_class($node) : \gettype($node)));
220 220
             }
221 221
 
@@ -225,7 +225,7 @@  discard block
 block discarded – undo
225 225
         }
226 226
 
227 227
         if ($metadata->xmlAttributeMap) {
228
-            if (!\is_array($v)) {
228
+            if ( ! \is_array($v)) {
229 229
                 throw new RuntimeException(sprintf('Unsupported value type for XML attribute map. Expected array but got %s.', \gettype($v)));
230 230
             }
231 231
 
@@ -234,7 +234,7 @@  discard block
 block discarded – undo
234 234
                 $node = $this->navigator->accept($value, null);
235 235
                 $this->revertCurrentMetadata();
236 236
 
237
-                if (!$node instanceof \DOMCharacterData) {
237
+                if ( ! $node instanceof \DOMCharacterData) {
238 238
                     throw new RuntimeException(sprintf('Unsupported value for a XML attribute map value. Expected character data, but got %s.', json_encode($v)));
239 239
                 }
240 240
 
@@ -244,7 +244,7 @@  discard block
 block discarded – undo
244 244
             return;
245 245
         }
246 246
 
247
-        if ($addEnclosingElement = !$this->isInLineCollection($metadata) && !$metadata->inline) {
247
+        if ($addEnclosingElement = ! $this->isInLineCollection($metadata) && ! $metadata->inline) {
248 248
 
249 249
             $namespace = null !== $metadata->xmlNamespace
250 250
                 ? $metadata->xmlNamespace
@@ -294,7 +294,7 @@  discard block
 block discarded – undo
294 294
 
295 295
     private function isSkippableEmptyObject($node, PropertyMetadata $metadata)
296 296
     {
297
-        return $node === null && !$metadata->xmlCollection && $metadata->skipWhenEmpty;
297
+        return $node === null && ! $metadata->xmlCollection && $metadata->skipWhenEmpty;
298 298
     }
299 299
 
300 300
     private function isSkippableCollection(PropertyMetadata $metadata)
@@ -304,7 +304,7 @@  discard block
 block discarded – undo
304 304
 
305 305
     private function isElementEmpty(\DOMElement $element)
306 306
     {
307
-        return !$element->hasChildNodes() && !$element->hasAttributes();
307
+        return ! $element->hasChildNodes() && ! $element->hasAttributes();
308 308
     }
309 309
 
310 310
     public function endVisitingObject(ClassMetadata $metadata, object $data, array $type)
@@ -411,7 +411,7 @@  discard block
 block discarded – undo
411 411
         foreach ($metadata->xmlNamespaces as $prefix => $uri) {
412 412
             $attribute = 'xmlns';
413 413
             if ($prefix !== '') {
414
-                $attribute .= ':' . $prefix;
414
+                $attribute .= ':'.$prefix;
415 415
             } elseif ($element->namespaceURI === $uri) {
416 416
                 continue;
417 417
             }
@@ -427,19 +427,19 @@  discard block
 block discarded – undo
427 427
         if ($this->currentNode->isDefaultNamespace($namespace)) {
428 428
             return $this->document->createElementNS($namespace, $tagName);
429 429
         }
430
-        if (!($prefix = $this->currentNode->lookupPrefix($namespace)) && !($prefix = $this->document->lookupPrefix($namespace))) {
431
-            $prefix = 'ns-' . substr(sha1($namespace), 0, 8);
430
+        if ( ! ($prefix = $this->currentNode->lookupPrefix($namespace)) && ! ($prefix = $this->document->lookupPrefix($namespace))) {
431
+            $prefix = 'ns-'.substr(sha1($namespace), 0, 8);
432 432
         }
433
-        return $this->document->createElementNS($namespace, $prefix . ':' . $tagName);
433
+        return $this->document->createElementNS($namespace, $prefix.':'.$tagName);
434 434
     }
435 435
 
436 436
     private function setAttributeOnNode(\DOMElement $node, $name, $value, $namespace = null)
437 437
     {
438 438
         if (null !== $namespace) {
439
-            if (!$prefix = $node->lookupPrefix($namespace)) {
440
-                $prefix = 'ns-' . substr(sha1($namespace), 0, 8);
439
+            if ( ! $prefix = $node->lookupPrefix($namespace)) {
440
+                $prefix = 'ns-'.substr(sha1($namespace), 0, 8);
441 441
             }
442
-            $node->setAttributeNS($namespace, $prefix . ':' . $name, $value);
442
+            $node->setAttributeNS($namespace, $prefix.':'.$name, $value);
443 443
         } else {
444 444
             $node->setAttribute($name, $value);
445 445
         }
Please login to merge, or discard this patch.
src/Serializer.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -162,7 +162,7 @@  discard block
 block discarded – undo
162 162
             $context = $this->serializationContextFactory->createSerializationContext();
163 163
         }
164 164
 
165
-        if (!isset($this->serializationVisitors[$format])) {
165
+        if ( ! isset($this->serializationVisitors[$format])) {
166 166
             throw new UnsupportedFormatException(sprintf('The format "%s" is not supported for serialization.', $format));
167 167
         }
168 168
 
@@ -181,7 +181,7 @@  discard block
 block discarded – undo
181 181
             $context = $this->deserializationContextFactory->createDeserializationContext();
182 182
         }
183 183
 
184
-        if (!isset($this->deserializationVisitors[$format])) {
184
+        if ( ! isset($this->deserializationVisitors[$format])) {
185 185
             throw new UnsupportedFormatException(sprintf('The format "%s" is not supported for deserialization.', $format));
186 186
         }
187 187
 
@@ -202,7 +202,7 @@  discard block
 block discarded – undo
202 202
             $context = $this->serializationContextFactory->createSerializationContext();
203 203
         }
204 204
 
205
-        if (!isset($this->serializationVisitors['json'])) {
205
+        if ( ! isset($this->serializationVisitors['json'])) {
206 206
             throw new UnsupportedFormatException(sprintf('The format "%s" is not supported for fromArray.', 'json'));
207 207
         }
208 208
 
@@ -214,7 +214,7 @@  discard block
 block discarded – undo
214 214
         $result = $this->visit($navigator, $visitor, $context, $data, 'json', $type);
215 215
         $result = $this->convertArrayObjects($result);
216 216
 
217
-        if (!\is_array($result)) {
217
+        if ( ! \is_array($result)) {
218 218
             throw new RuntimeException(sprintf(
219 219
                 'The input data of type "%s" did not convert to an array, but got a result of type "%s".',
220 220
                 \is_object($data) ? \get_class($data) : \gettype($data),
@@ -234,7 +234,7 @@  discard block
 block discarded – undo
234 234
             $context = $this->deserializationContextFactory->createDeserializationContext();
235 235
         }
236 236
 
237
-        if (!isset($this->deserializationVisitors['json'])) {
237
+        if ( ! isset($this->deserializationVisitors['json'])) {
238 238
             throw new UnsupportedFormatException(sprintf('The format "%s" is not supported for fromArray.', 'json'));
239 239
         }
240 240
 
@@ -265,7 +265,7 @@  discard block
 block discarded – undo
265 265
     private function convertArrayObjects($data)
266 266
     {
267 267
         if ($data instanceof \ArrayObject || $data instanceof \stdClass) {
268
-            $data = (array)$data;
268
+            $data = (array) $data;
269 269
         }
270 270
         if (\is_array($data)) {
271 271
             foreach ($data as $k => $v) {
Please login to merge, or discard this patch.
src/DeserializationGraphNavigator.php 2 patches
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -153,11 +153,11 @@  discard block
 block discarded – undo
153 153
                 /** @var $metadata ClassMetadata */
154 154
                 $metadata = $this->metadataFactory->getMetadataForClass($type['name']);
155 155
 
156
-                if ($metadata->usingExpression && !$this->expressionExclusionStrategy) {
156
+                if ($metadata->usingExpression && ! $this->expressionExclusionStrategy) {
157 157
                     throw new ExpressionLanguageRequiredException("To use conditional exclude/expose in {$metadata->name} you must configure the expression language.");
158 158
                 }
159 159
 
160
-                if (!empty($metadata->discriminatorMap) && $type['name'] === $metadata->discriminatorBaseClass) {
160
+                if ( ! empty($metadata->discriminatorMap) && $type['name'] === $metadata->discriminatorBaseClass) {
161 161
                     $metadata = $this->resolveMetadata($data, $metadata);
162 162
                 }
163 163
 
@@ -189,7 +189,7 @@  discard block
 block discarded – undo
189 189
                     try {
190 190
                         $v = $this->visitor->visitProperty($propertyMetadata, $data);
191 191
                         $this->accessor->setValue($object, $v, $propertyMetadata);
192
-                    }catch (NotAcceptableException $e){
192
+                    } catch (NotAcceptableException $e) {
193 193
 
194 194
                     }
195 195
                     $this->context->popPropertyMetadata();
@@ -206,7 +206,7 @@  discard block
 block discarded – undo
206 206
     {
207 207
         $typeValue = $this->visitor->visitDiscriminatorMapProperty($data, $metadata);
208 208
 
209
-        if (!isset($metadata->discriminatorMap[$typeValue])) {
209
+        if ( ! isset($metadata->discriminatorMap[$typeValue])) {
210 210
             throw new LogicException(sprintf(
211 211
                 'The type value "%s" does not exist in the discriminator map of class "%s". Available types: %s',
212 212
                 $typeValue,
Please login to merge, or discard this patch.
Braces   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -189,7 +189,7 @@
 block discarded – undo
189 189
                     try {
190 190
                         $v = $this->visitor->visitProperty($propertyMetadata, $data);
191 191
                         $this->accessor->setValue($object, $v, $propertyMetadata);
192
-                    }catch (NotAcceptableException $e){
192
+                    } catch (NotAcceptableException $e) {
193 193
 
194 194
                     }
195 195
                     $this->context->popPropertyMetadata();
Please login to merge, or discard this patch.