Please note that this service is under alpha statement, we are actively working on it. It may be unstable and might completely change without warning. Help us by reporting!

sigmapix/SigmapixSonataImportBundle

Analysis #10388 FAILED

Diff

Download raw diff

diff --git a/Admin/ImportableAdminTrait.php b/Admin/ImportableAdminTrait.php
index a7cc6b70f32f6331ba6bc31867b13c81d0c4765d..3c751ae927c535dbf0b59372b27e0e57ea306cd2 100644
--- a/Admin/ImportableAdminTrait.php
+++ b/Admin/ImportableAdminTrait.php
@@ -113,7 +113,7 @@ trait ImportableAdminTrait
                     'mapped' => $field->getOption('mapped'),
                     'label' => $field->getOption('label'),
                     'label_format' => $field->getOption('label_format'), // This will be used for DateTimeConverter
-                    'translation_domain' => $field->getOption('translation_domain')
+                    'translation_domain' => $field->getOption('translation_domain'),
                 ]);
             }
         }
diff --git a/Controller/CRUDController.php b/Controller/CRUDController.php
index ff5a6cb83c2e9e6540fae4570e23729cf75de3d7..af9ab7179ea1f70ef789cced777733480dbdcd13 100644
--- a/Controller/CRUDController.php
+++ b/Controller/CRUDController.php
@@ -56,7 +56,7 @@ class CRUDController extends Controller
             $exporter = $this->get('sonata.exporter.exporter');
         }
 
-        if (!in_array($format, $allowedExportFormats)) {
+        if (!\in_array($format, $allowedExportFormats)) {
             throw new \RuntimeException(
                 sprintf(
                     'Export in format `%s` is not allowed for class: `%s`. Allowed formats are: `%s`',
diff --git a/Service/ImportService.php b/Service/ImportService.php
index f11d1ed6c859bd66849e4d487f378a1c27107cbd..fd9e8bb4245d7eef7804f39329d6755e9ee6963f 100644
--- a/Service/ImportService.php
+++ b/Service/ImportService.php
@@ -62,20 +62,8 @@ final class ImportService
         $reader = $this->getReader($file);
         $headers = array_flip($this->fixHeadersEncoding($reader));
         array_walk($headers, function (&$v, $k) use ($headers) { $v = $k; });
-        return $headers;
-    }
 
-    private function fixHeadersEncoding($reader)
-    {
-        $columnHeaders = array_filter($reader->getColumnHeaders(), function ($h) {return null !== $h; });
-        $columnHeaders = array_map(
-            function ($h) {
-                if (!empty($h) && is_string($h) && mb_detect_encoding($h) !== 'UTF-8') {
-                    $h = utf8_encode($h);
-                }
-                return trim($h);
-            }, $columnHeaders);
-        return $columnHeaders;
+        return $headers;
     }
 
     /**
@@ -99,12 +87,13 @@ final class ImportService
         // Replace columnsHeader names with entity field name in our $mapping
         $columnHeaders = array_map(function ($h) use ($mapping) {
             $k = array_search($h, (array) $mapping, true);
+
             return false === $k ? $h : $k;
         }, $this->fixHeadersEncoding($reader));
         $reader->setColumnHeaders($columnHeaders);
 
         /** @var DoctrineWriter $writer */
-        $writer = new $this->doctrineWriterClass($this->em, get_class($form->getData()));
+        $writer = new $this->doctrineWriterClass($this->em, \get_class($form->getData()));
         if (method_exists($writer, 'setContainer')) {
             $writer->setContainer($this->container);
         }
@@ -141,6 +130,21 @@ final class ImportService
         return $this;
     }
 
+    private function fixHeadersEncoding($reader)
+    {
+        $columnHeaders = array_filter($reader->getColumnHeaders(), function ($h) {return null !== $h; });
+        $columnHeaders = array_map(
+            function ($h) {
+                if (!empty($h) && \is_string($h) && 'UTF-8' !== mb_detect_encoding($h)) {
+                    $h = utf8_encode($h);
+                }
+
+                return trim($h);
+            }, $columnHeaders);
+
+        return $columnHeaders;
+    }
+
     /**
      * @param UploadedFile $file
      *
@@ -152,7 +156,7 @@ final class ImportService
         $fileExtension = $file->guessExtension();
         $excelExtensions = ['xls', 'xlsx', 'zip'];
 
-        if (in_array($fileExtension, $excelExtensions)) {
+        if (\in_array($fileExtension, $excelExtensions)) {
             $reader = new ExcelReader(new \SplFileObject($pathFile), 0, 0, true);
         } else {
             $reader = new CsvReader(new \SplFileObject($pathFile), ';');