diff vendor/symfony/serializer/Encoder/CsvEncoder.php @ 17:129ea1e6d783

Update, including to Drupal core 8.6.10
author Chris Cannam
date Thu, 28 Feb 2019 13:21:36 +0000
parents 1fec387a4317
children
line wrap: on
line diff
--- a/vendor/symfony/serializer/Encoder/CsvEncoder.php	Tue Jul 10 15:07:59 2018 +0100
+++ b/vendor/symfony/serializer/Encoder/CsvEncoder.php	Thu Feb 28 13:21:36 2019 +0000
@@ -50,20 +50,20 @@
     /**
      * {@inheritdoc}
      */
-    public function encode($data, $format, array $context = array())
+    public function encode($data, $format, array $context = [])
     {
         $handle = fopen('php://temp,', 'w+');
 
-        if (!is_array($data)) {
-            $data = array(array($data));
+        if (!\is_array($data)) {
+            $data = [[$data]];
         } elseif (empty($data)) {
-            $data = array(array());
+            $data = [[]];
         } else {
             // Sequential arrays of arrays are considered as collections
             $i = 0;
             foreach ($data as $key => $value) {
-                if ($i !== $key || !is_array($value)) {
-                    $data = array($data);
+                if ($i !== $key || !\is_array($value)) {
+                    $data = [$data];
                     break;
                 }
 
@@ -74,7 +74,7 @@
         list($delimiter, $enclosure, $escapeChar, $keySeparator, $headers) = $this->getCsvOptions($context);
 
         foreach ($data as &$value) {
-            $flattened = array();
+            $flattened = [];
             $this->flatten($value, $flattened, $keySeparator);
             $value = $flattened;
         }
@@ -107,7 +107,7 @@
     /**
      * {@inheritdoc}
      */
-    public function decode($data, $format, array $context = array())
+    public function decode($data, $format, array $context = [])
     {
         $handle = fopen('php://temp', 'r+');
         fwrite($handle, $data);
@@ -115,13 +115,13 @@
 
         $headers = null;
         $nbHeaders = 0;
-        $headerCount = array();
-        $result = array();
+        $headerCount = [];
+        $result = [];
 
         list($delimiter, $enclosure, $escapeChar, $keySeparator) = $this->getCsvOptions($context);
 
         while (false !== ($cols = fgetcsv($handle, 0, $delimiter, $enclosure, $escapeChar))) {
-            $nbCols = count($cols);
+            $nbCols = \count($cols);
 
             if (null === $headers) {
                 $nbHeaders = $nbCols;
@@ -129,13 +129,13 @@
                 foreach ($cols as $col) {
                     $header = explode($keySeparator, $col);
                     $headers[] = $header;
-                    $headerCount[] = count($header);
+                    $headerCount[] = \count($header);
                 }
 
                 continue;
             }
 
-            $item = array();
+            $item = [];
             for ($i = 0; ($i < $nbCols) && ($i < $nbHeaders); ++$i) {
                 $depth = $headerCount[$i];
                 $arr = &$item;
@@ -148,7 +148,7 @@
                     }
 
                     if (!isset($arr[$headers[$i][$j]])) {
-                        $arr[$headers[$i][$j]] = array();
+                        $arr[$headers[$i][$j]] = [];
                     }
 
                     $arr = &$arr[$headers[$i][$j]];
@@ -186,7 +186,7 @@
     private function flatten(array $array, array &$result, $keySeparator, $parentKey = '')
     {
         foreach ($array as $key => $value) {
-            if (is_array($value)) {
+            if (\is_array($value)) {
                 $this->flatten($value, $result, $keySeparator, $parentKey.$key.$keySeparator);
             } else {
                 $result[$parentKey.$key] = $value;
@@ -200,13 +200,13 @@
         $enclosure = isset($context[self::ENCLOSURE_KEY]) ? $context[self::ENCLOSURE_KEY] : $this->enclosure;
         $escapeChar = isset($context[self::ESCAPE_CHAR_KEY]) ? $context[self::ESCAPE_CHAR_KEY] : $this->escapeChar;
         $keySeparator = isset($context[self::KEY_SEPARATOR_KEY]) ? $context[self::KEY_SEPARATOR_KEY] : $this->keySeparator;
-        $headers = isset($context[self::HEADERS_KEY]) ? $context[self::HEADERS_KEY] : array();
+        $headers = isset($context[self::HEADERS_KEY]) ? $context[self::HEADERS_KEY] : [];
 
-        if (!is_array($headers)) {
-            throw new InvalidArgumentException(sprintf('The "%s" context variable must be an array or null, given "%s".', self::HEADERS_KEY, gettype($headers)));
+        if (!\is_array($headers)) {
+            throw new InvalidArgumentException(sprintf('The "%s" context variable must be an array or null, given "%s".', self::HEADERS_KEY, \gettype($headers)));
         }
 
-        return array($delimiter, $enclosure, $escapeChar, $keySeparator, $headers);
+        return [$delimiter, $enclosure, $escapeChar, $keySeparator, $headers];
     }
 
     /**
@@ -214,8 +214,8 @@
      */
     private function extractHeaders(array $data)
     {
-        $headers = array();
-        $flippedHeaders = array();
+        $headers = [];
+        $flippedHeaders = [];
 
         foreach ($data as $row) {
             $previousHeader = null;
@@ -227,11 +227,11 @@
                 }
 
                 if (null === $previousHeader) {
-                    $n = count($headers);
+                    $n = \count($headers);
                 } else {
                     $n = $flippedHeaders[$previousHeader] + 1;
 
-                    for ($j = count($headers); $j > $n; --$j) {
+                    for ($j = \count($headers); $j > $n; --$j) {
                         ++$flippedHeaders[$headers[$j] = $headers[$j - 1]];
                     }
                 }