Test Setup Failed
Branch master (0ff4f4)
by Christopher
06:18
created
src/POData/UriProcessor/XML2Array.php 1 patch
Indentation   +68 added lines, -68 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
 
4 4
 class XML2Array {
5 5
     private static $xml = null;
6
-	private static $encoding = 'UTF-8';
6
+    private static $encoding = 'UTF-8';
7 7
     /**
8 8
      * Initialize the root XML node [optional]
9 9
      * @param $version
@@ -13,7 +13,7 @@  discard block
 block discarded – undo
13 13
     public static function init($version = '1.0', $encoding = 'UTF-8', $format_output = true) {
14 14
         self::$xml = new \DOMDocument($version, $encoding);
15 15
         self::$xml->formatOutput = $format_output;
16
-		self::$encoding = $encoding;
16
+        self::$encoding = $encoding;
17 17
     }
18 18
     /**
19 19
      * Convert an XML to Array
@@ -23,18 +23,18 @@  discard block
 block discarded – undo
23 23
      */
24 24
     public static function &createArray($input_xml) {
25 25
         $xml = self::getXMLRoot();
26
-		if(is_string($input_xml)) {
27
-			$parsed = $xml->loadXML($input_xml);
28
-			if(!$parsed) {
29
-				throw new \Exception('[XML2Array] Error parsing the XML string.');
30
-			}
31
-		} else {
32
-			if(get_class($input_xml) != 'DOMDocument') {
33
-				throw new \Exception('[XML2Array] The input XML object should be of type: DOMDocument.');
34
-			}
35
-			$xml = self::$xml = $input_xml;
36
-		}
37
-		$array[$xml->documentElement->tagName] = self::convert($xml->documentElement);
26
+        if(is_string($input_xml)) {
27
+            $parsed = $xml->loadXML($input_xml);
28
+            if(!$parsed) {
29
+                throw new \Exception('[XML2Array] Error parsing the XML string.');
30
+            }
31
+        } else {
32
+            if(get_class($input_xml) != 'DOMDocument') {
33
+                throw new \Exception('[XML2Array] The input XML object should be of type: DOMDocument.');
34
+            }
35
+            $xml = self::$xml = $input_xml;
36
+        }
37
+        $array[$xml->documentElement->tagName] = self::convert($xml->documentElement);
38 38
         self::$xml = null;    // clear the xml node in the class for 2nd time use.
39 39
         return $array;
40 40
     }
@@ -44,60 +44,60 @@  discard block
 block discarded – undo
44 44
      * @return mixed
45 45
      */
46 46
     private static function &convert($node) {
47
-		$output = array();
48
-		switch ($node->nodeType) {
49
-			case XML_CDATA_SECTION_NODE:
50
-				$output['@cdata'] = trim($node->textContent);
51
-				break;
52
-			case XML_TEXT_NODE:
53
-				$output = trim($node->textContent);
54
-				break;
55
-			case XML_ELEMENT_NODE:
56
-				// for each child node, call the covert function recursively
57
-				for ($i=0, $m=$node->childNodes->length; $i<$m; $i++) {
58
-					$child = $node->childNodes->item($i);
59
-					$v = self::convert($child);
60
-					if(isset($child->tagName)) {
61
-						$t = $child->tagName;
62
-						// assume more nodes of same kind are coming
63
-						if(!isset($output[$t])) {
64
-							$output[$t] = array();
65
-						}
66
-						$output[$t][] = $v;
67
-					} else {
68
-						//check if it is not an empty text node
69
-						if($v !== '') {
70
-							$output = $v;
71
-						}
72
-					}
73
-				}
74
-				if(is_array($output)) {
75
-					// if only one node of its kind, assign it directly instead if array($value);
76
-					foreach ($output as $t => $v) {
77
-						if(is_array($v) && count($v)==1) {
78
-							$output[$t] = $v[0];
79
-						}
80
-					}
81
-					if(empty($output)) {
82
-						//for empty nodes
83
-						$output = '';
84
-					}
85
-				}
86
-				// loop through the attributes and collect them
87
-				if($node->attributes->length) {
88
-					$a = array();
89
-					foreach($node->attributes as $attrName => $attrNode) {
90
-						$a[$attrName] = (string) $attrNode->value;
91
-					}
92
-					// if its an leaf node, store the value in @value instead of directly storing it.
93
-					if(!is_array($output)) {
94
-						$output = array('@value' => $output);
95
-					}
96
-					$output['@attributes'] = $a;
97
-				}
98
-				break;
99
-		}
100
-		return $output;
47
+        $output = array();
48
+        switch ($node->nodeType) {
49
+            case XML_CDATA_SECTION_NODE:
50
+                $output['@cdata'] = trim($node->textContent);
51
+                break;
52
+            case XML_TEXT_NODE:
53
+                $output = trim($node->textContent);
54
+                break;
55
+            case XML_ELEMENT_NODE:
56
+                // for each child node, call the covert function recursively
57
+                for ($i=0, $m=$node->childNodes->length; $i<$m; $i++) {
58
+                    $child = $node->childNodes->item($i);
59
+                    $v = self::convert($child);
60
+                    if(isset($child->tagName)) {
61
+                        $t = $child->tagName;
62
+                        // assume more nodes of same kind are coming
63
+                        if(!isset($output[$t])) {
64
+                            $output[$t] = array();
65
+                        }
66
+                        $output[$t][] = $v;
67
+                    } else {
68
+                        //check if it is not an empty text node
69
+                        if($v !== '') {
70
+                            $output = $v;
71
+                        }
72
+                    }
73
+                }
74
+                if(is_array($output)) {
75
+                    // if only one node of its kind, assign it directly instead if array($value);
76
+                    foreach ($output as $t => $v) {
77
+                        if(is_array($v) && count($v)==1) {
78
+                            $output[$t] = $v[0];
79
+                        }
80
+                    }
81
+                    if(empty($output)) {
82
+                        //for empty nodes
83
+                        $output = '';
84
+                    }
85
+                }
86
+                // loop through the attributes and collect them
87
+                if($node->attributes->length) {
88
+                    $a = array();
89
+                    foreach($node->attributes as $attrName => $attrNode) {
90
+                        $a[$attrName] = (string) $attrNode->value;
91
+                    }
92
+                    // if its an leaf node, store the value in @value instead of directly storing it.
93
+                    if(!is_array($output)) {
94
+                        $output = array('@value' => $output);
95
+                    }
96
+                    $output['@attributes'] = $a;
97
+                }
98
+                break;
99
+        }
100
+        return $output;
101 101
     }
102 102
     /*
103 103
      * Get the root XML node, if there isn't one, create it.
Please login to merge, or discard this patch.
services/NorthWind/NorthWindDSExpressionProvider.php 1 patch
Switch Indentation   +91 added lines, -91 removed lines patch added patch discarded remove patch
@@ -294,103 +294,103 @@
 block discarded – undo
294 294
     public function onFunctionCallExpression($functionDescription, $params)
295 295
     {
296 296
         switch ($functionDescription->functionName) {
297
-        case ODataConstants::STRFUN_COMPARE:
298
-            return "STRCMP($params[0]; $params[1])";
299
-            break;
300
-        case ODataConstants::STRFUN_ENDSWITH:
301
-          return "(($params[1]) = RIGHT(($params[0]), LEN($params[1])))";
302
-            break;
303
-        case ODataConstants::STRFUN_INDEXOF:
304
-          // In SQLServer the index of string starts from 1, but in OData
305
-          // the string start with index 0, so the below subtraction of 1
306
-          return "(CHARINDEX($params[1], $params[0]) - 1)";
307
-            break;
308
-        case ODataConstants::STRFUN_REPLACE:
309
-          return "REPLACE($params[0], $params[1], $params[2])";
310
-            break;
311
-        case ODataConstants::STRFUN_STARTSWITH:
312
-          return "(($params[1]) = LEFT(($params[0]), LEN($params[1])))";
313
-            break;
314
-        case ODataConstants::STRFUN_TOLOWER:
315
-          return "LOWER($params[0])";
316
-            break;
317
-        case ODataConstants::STRFUN_TOUPPER:
318
-          return "UPPER($params[0])";
319
-            break;
320
-        case ODataConstants::STRFUN_TRIM:
321
-          // OData supports trim function
322
-          // We don't have the same function SQL Server, so use SQL functions LTRIM and RTRIM together
323
-          // to achieve TRIM functionality.
324
-          return "RTRIM(LTRIM($params[0]))";
325
-            break;
326
-        case ODataConstants::STRFUN_SUBSTRING:
327
-          if (count($params) == 3) {
328
-                // 3 Param version of OData substring
329
-                return "SUBSTRING($params[0], $params[1] + 1, $params[2])";
330
-            } else {
331
-                // 2 Params version of OData substring
332
-            // We don't have the same function for SQL Server, we have only:
297
+            case ODataConstants::STRFUN_COMPARE:
298
+                return "STRCMP($params[0]; $params[1])";
299
+                break;
300
+            case ODataConstants::STRFUN_ENDSWITH:
301
+              return "(($params[1]) = RIGHT(($params[0]), LEN($params[1])))";
302
+                break;
303
+            case ODataConstants::STRFUN_INDEXOF:
304
+              // In SQLServer the index of string starts from 1, but in OData
305
+              // the string start with index 0, so the below subtraction of 1
306
+              return "(CHARINDEX($params[1], $params[0]) - 1)";
307
+                break;
308
+            case ODataConstants::STRFUN_REPLACE:
309
+              return "REPLACE($params[0], $params[1], $params[2])";
310
+                break;
311
+            case ODataConstants::STRFUN_STARTSWITH:
312
+              return "(($params[1]) = LEFT(($params[0]), LEN($params[1])))";
313
+                break;
314
+            case ODataConstants::STRFUN_TOLOWER:
315
+              return "LOWER($params[0])";
316
+                break;
317
+            case ODataConstants::STRFUN_TOUPPER:
318
+              return "UPPER($params[0])";
319
+                break;
320
+            case ODataConstants::STRFUN_TRIM:
321
+              // OData supports trim function
322
+              // We don't have the same function SQL Server, so use SQL functions LTRIM and RTRIM together
323
+              // to achieve TRIM functionality.
324
+              return "RTRIM(LTRIM($params[0]))";
325
+                break;
326
+            case ODataConstants::STRFUN_SUBSTRING:
327
+              if (count($params) == 3) {
328
+                    // 3 Param version of OData substring
329
+                    return "SUBSTRING($params[0], $params[1] + 1, $params[2])";
330
+                } else {
331
+                    // 2 Params version of OData substring
332
+                // We don't have the same function for SQL Server, we have only:
333 333
 
334
-            // SUBSTRING ( value_expression , start_expression , length_expression )
335
-            // http://msdn.microsoft.com/en-us/library/ms187748.aspx
334
+                // SUBSTRING ( value_expression , start_expression , length_expression )
335
+                // http://msdn.microsoft.com/en-us/library/ms187748.aspx
336 336
 
337
-            // If the sum of start_expression and length_expression is greater than the number of characters
338
-            // in value_expression, the whole value expression beginning at start_expression is returned
339
-            // In OData substring function the index start from 0, in SQL Server its from 1
340
-            return "SUBSTRING($params[0], $params[1] + 1, LEN($params[0]))";
341
-            }
342
-            break;
343
-        case ODataConstants::STRFUN_SUBSTRINGOF:
344
-          return "(CHARINDEX($params[0], $params[1]) != 0)";
345
-            break;
346
-        case ODataConstants::STRFUN_CONCAT:
347
-            return "$params[0] + $params[1]";
348
-            break;
349
-        case ODataConstants::STRFUN_LENGTH:
350
-            return "LEN($params[0])";
351
-            break;
352
-        case ODataConstants::GUIDFUN_EQUAL:
353
-            return "($params[0] = $params[1])";
354
-            break;
355
-        case ODataConstants::DATETIME_COMPARE:
356
-            return "DATETIMECMP($params[0]; $params[1])";
357
-            break;
358
-        case ODataConstants::DATETIME_YEAR:
359
-            return "YEAR($params[0])";
360
-            break;
361
-        case ODataConstants::DATETIME_MONTH:
362
-            return "MONTH($params[0])";
363
-            break;
364
-        case ODataConstants::DATETIME_DAY:
365
-            return "DAY($params[0])";
366
-            break;
367
-        case ODataConstants::DATETIME_HOUR:
368
-            return "DATENAME(HOUR, $params[0])";
369
-            break;
370
-        case ODataConstants::DATETIME_MINUTE:
371
-            return "DATENAME(MINUTE, $params[0])";
372
-            break;
373
-        case ODataConstants::DATETIME_SECOND:
374
-            return "DATENAME(SECOND, $params[0])";
375
-            break;
376
-        case ODataConstants::MATHFUN_ROUND:
377
-            return "ROUND($params[0], $this->_default_round)";
378
-            break;
379
-        case ODataConstants::MATHFUN_CEILING:
380
-            return "CEILING($params[0])";
381
-            break;
382
-        case ODataConstants::MATHFUN_FLOOR:
383
-            return "FLOOR($params[0])";
384
-            break;
385
-        case ODataConstants::BINFUL_EQUAL:
386
-            return "($params[0] = $params[1])";
387
-            break;
337
+                // If the sum of start_expression and length_expression is greater than the number of characters
338
+                // in value_expression, the whole value expression beginning at start_expression is returned
339
+                // In OData substring function the index start from 0, in SQL Server its from 1
340
+                return "SUBSTRING($params[0], $params[1] + 1, LEN($params[0]))";
341
+                }
342
+                break;
343
+            case ODataConstants::STRFUN_SUBSTRINGOF:
344
+              return "(CHARINDEX($params[0], $params[1]) != 0)";
345
+                break;
346
+            case ODataConstants::STRFUN_CONCAT:
347
+                return "$params[0] + $params[1]";
348
+                break;
349
+            case ODataConstants::STRFUN_LENGTH:
350
+                return "LEN($params[0])";
351
+                break;
352
+            case ODataConstants::GUIDFUN_EQUAL:
353
+                return "($params[0] = $params[1])";
354
+                break;
355
+            case ODataConstants::DATETIME_COMPARE:
356
+                return "DATETIMECMP($params[0]; $params[1])";
357
+                break;
358
+            case ODataConstants::DATETIME_YEAR:
359
+                return "YEAR($params[0])";
360
+                break;
361
+            case ODataConstants::DATETIME_MONTH:
362
+                return "MONTH($params[0])";
363
+                break;
364
+            case ODataConstants::DATETIME_DAY:
365
+                return "DAY($params[0])";
366
+                break;
367
+            case ODataConstants::DATETIME_HOUR:
368
+                return "DATENAME(HOUR, $params[0])";
369
+                break;
370
+            case ODataConstants::DATETIME_MINUTE:
371
+                return "DATENAME(MINUTE, $params[0])";
372
+                break;
373
+            case ODataConstants::DATETIME_SECOND:
374
+                return "DATENAME(SECOND, $params[0])";
375
+                break;
376
+            case ODataConstants::MATHFUN_ROUND:
377
+                return "ROUND($params[0], $this->_default_round)";
378
+                break;
379
+            case ODataConstants::MATHFUN_CEILING:
380
+                return "CEILING($params[0])";
381
+                break;
382
+            case ODataConstants::MATHFUN_FLOOR:
383
+                return "FLOOR($params[0])";
384
+                break;
385
+            case ODataConstants::BINFUL_EQUAL:
386
+                return "($params[0] = $params[1])";
387
+                break;
388 388
             case 'is_null':
389 389
             return "is_null($params[0])";
390 390
             break;
391 391
 
392
-        default:
393
-            throw new \InvalidArgumentException('onFunctionCallExpression');
392
+            default:
393
+                throw new \InvalidArgumentException('onFunctionCallExpression');
394 394
         }
395 395
     }
396 396
 
Please login to merge, or discard this patch.