From 14e5a242e137254a828c3d95e4a73f06c8db8e47 Mon Sep 17 00:00:00 2001
From: "florian.azizian" <florian.azizian@maarch.org>
Date: Sat, 15 Feb 2020 13:13:28 +0100
Subject: [PATCH] FEAT return array json_decode

---
 .../controllers/ConfigurationController.php   |  4 ++--
 src/app/email/controllers/EmailController.php |  4 ++--
 .../SendMessageExchangeController.php         |  2 +-
 .../resource/controllers/ExportController.php |  8 ++++----
 .../ShippingTemplateController.php            |  8 ++++----
 .../attachment/AttachmentControllerTest.php   | 20 +++++++++----------
 6 files changed, 23 insertions(+), 23 deletions(-)

diff --git a/src/app/configuration/controllers/ConfigurationController.php b/src/app/configuration/controllers/ConfigurationController.php
index 1d76b6e78c4..4ab7b2a3c59 100755
--- a/src/app/configuration/controllers/ConfigurationController.php
+++ b/src/app/configuration/controllers/ConfigurationController.php
@@ -30,7 +30,7 @@ class ConfigurationController
         }
 
         $configuration = ConfigurationModel::getByService(['service' => $aArgs['service']]);
-        $configuration['value'] = (array)json_decode($configuration['value']);
+        $configuration['value'] = json_decode($configuration['value'], true);
         if (!empty($configuration['value']['password'])) {
             $configuration['value']['password'] = '';
             $configuration['value']['passwordAlreadyExists'] = true;
@@ -56,7 +56,7 @@ class ConfigurationController
         if ($aArgs['service'] == 'admin_email_server') {
             if ($data['auth'] && empty($data['password'])) {
                 $configuration = ConfigurationModel::getByService(['service' => $aArgs['service']]);
-                $configuration['value'] = (array)json_decode($configuration['value']);
+                $configuration['value'] = json_decode($configuration['value'], true);
                 if (!empty($configuration['value']['password'])) {
                     $data['password'] = $configuration['value']['password'];
                 }
diff --git a/src/app/email/controllers/EmailController.php b/src/app/email/controllers/EmailController.php
index a093f043838..2989c2056ec 100644
--- a/src/app/email/controllers/EmailController.php
+++ b/src/app/email/controllers/EmailController.php
@@ -527,7 +527,7 @@ class EmailController
         ValidatorModel::intVal($args, ['emailId', 'userId']);
 
         $email = EmailModel::getById(['id' => $args['emailId']]);
-        $email['sender']        = (array)json_decode($email['sender']);
+        $email['sender']        = json_decode($email['sender'], true);
         $email['recipients']    = array_unique(json_decode($email['recipients']));
         $email['cc']            = array_unique(json_decode($email['cc']));
         $email['cci']           = array_unique(json_decode($email['cci']));
@@ -544,7 +544,7 @@ class EmailController
         }
 
         $configuration = ConfigurationModel::getByService(['service' => 'admin_email_server', 'select' => ['value']]);
-        $configuration = (array)json_decode($configuration['value']);
+        $configuration = json_decode($configuration['value'], true);
         if (empty($configuration)) {
             return ['errors' => 'Configuration is missing'];
         }
diff --git a/src/app/external/messageExchange/controllers/SendMessageExchangeController.php b/src/app/external/messageExchange/controllers/SendMessageExchangeController.php
index 7552c77fdf0..00971c4b45b 100755
--- a/src/app/external/messageExchange/controllers/SendMessageExchangeController.php
+++ b/src/app/external/messageExchange/controllers/SendMessageExchangeController.php
@@ -473,7 +473,7 @@ class SendMessageExchangeController
     {
         $archivalAgencyObject                    = new \stdClass();
         $archivalAgencyObject->Identifier        = new \stdClass();
-        $externalId = (array)json_decode($aArgs['ArchivalAgency']['ContactInformations']['external_id']);
+        $externalId = json_decode($aArgs['ArchivalAgency']['ContactInformations']['external_id'], true);
         $archivalAgencyObject->Identifier->value = $externalId['m2m'];
 
         $archivalAgencyObject->OrganizationDescriptiveMetadata       = new \stdClass();
diff --git a/src/app/resource/controllers/ExportController.php b/src/app/resource/controllers/ExportController.php
index 79020c633fc..44f440317b9 100644
--- a/src/app/resource/controllers/ExportController.php
+++ b/src/app/resource/controllers/ExportController.php
@@ -49,9 +49,9 @@ class ExportController
         $templates = ['pdf' => ['data' => []], 'csv' => ['data' => []]];
         foreach ($rawTemplates as $rawTemplate) {
             if ($rawTemplate['format'] == 'pdf') {
-                $templates['pdf'] = ['data' => (array)json_decode($rawTemplate['data'])];
+                $templates['pdf'] = ['data' => json_decode($rawTemplate['data'], true)];
             } elseif ($rawTemplate['format'] == 'csv') {
-                $templates['csv'] = ['delimiter' => $rawTemplate['delimiter'], 'data' => (array)json_decode($rawTemplate['data'])];
+                $templates['csv'] = ['delimiter' => $rawTemplate['delimiter'], 'data' => json_decode($rawTemplate['data'], true)];
             }
         }
 
@@ -290,7 +290,7 @@ class ExportController
                 }
             }
 
-            foreach($csvContent as $key => $value) {
+            foreach ($csvContent as $key => $value) {
                 $csvContent[$key] = utf8_decode($value);
             }
             fputcsv($file, $csvContent, $delimiter);
@@ -354,7 +354,7 @@ class ExportController
                         $content[] = str_replace('rest/', "apps/maarch_entreprise/index.php?page=details&dir=indexing_searching&id={$resource['res_id']}", \Url::coreurl());
                     } elseif ($value['value'] == 'getParentFolder') {
                         $content[] = ExportController::getParentFolderLabel(['res_id' => $resource['res_id']]);
-                    }  elseif ($value['value'] == 'getFolder') {
+                    } elseif ($value['value'] == 'getFolder') {
                         $content[] = ExportController::getFolderLabel(['res_id' => $resource['res_id']]);
                     } elseif ($value['value'] == 'getCategory') {
                         $content[] = ResModel::getCategoryLabel(['categoryId' => $resource['category_id']]);
diff --git a/src/app/shipping/controllers/ShippingTemplateController.php b/src/app/shipping/controllers/ShippingTemplateController.php
index 73fb94e9940..0d6b2af6a8f 100755
--- a/src/app/shipping/controllers/ShippingTemplateController.php
+++ b/src/app/shipping/controllers/ShippingTemplateController.php
@@ -50,11 +50,11 @@ class ShippingTemplateController
             return $response->withStatus(400)->withJson(['errors' => 'Shipping does not exist']);
         }
         
-        $shippingInfo['account'] = (array)json_decode($shippingInfo['account']);
+        $shippingInfo['account'] = json_decode($shippingInfo['account'], true);
         $shippingInfo['account']['password'] = '';
-        $shippingInfo['options']  = (array)json_decode($shippingInfo['options']);
-        $shippingInfo['fee']      = (array)json_decode($shippingInfo['fee']);
-        $shippingInfo['entities'] = (array)json_decode($shippingInfo['entities']);
+        $shippingInfo['options']  = json_decode($shippingInfo['options'], true);
+        $shippingInfo['fee']      = json_decode($shippingInfo['fee'], true);
+        $shippingInfo['entities'] = json_decode($shippingInfo['entities'], true);
 
         $allEntities = EntityModel::get([
             'select'    => ['e1.id', 'e1.entity_id', 'e1.entity_label', 'e2.id as parent_id'],
diff --git a/test/unitTests/app/attachment/AttachmentControllerTest.php b/test/unitTests/app/attachment/AttachmentControllerTest.php
index 266791c5af4..57966df1874 100644
--- a/test/unitTests/app/attachment/AttachmentControllerTest.php
+++ b/test/unitTests/app/attachment/AttachmentControllerTest.php
@@ -48,7 +48,7 @@ class AttachmentControllerTest extends TestCase
         $fullRequest = \httpRequestCustom::addContentInBody($aArgsFail, $request);
         $response = $attachmentController->create($fullRequest, new \Slim\Http\Response());
         $this->assertSame(400, $response->getStatusCode());
-        $response = (array)json_decode((string)$response->getBody());
+        $response = json_decode((string)$response->getBody(), true);
 
         $this->assertSame('Body type is empty or not a string', $response['errors']);
 
@@ -99,13 +99,13 @@ class AttachmentControllerTest extends TestCase
 
         $response     = $attachmentController->update($fullRequest, new \Slim\Http\Response(), ['id' => self::$id]);
         $this->assertSame(400, $response->getStatusCode());
-        $response = (array)json_decode((string)$response->getBody());
+        $response = json_decode((string)$response->getBody(), true);
 
         $this->assertSame('Body type is empty or not a string', $response['errors']);
 
         //  READ
         $response = $attachmentController->getById($request, new \Slim\Http\Response(), ['id' => self::$id]);
-        $res = (array)json_decode((string)$response->getBody());
+        $res = json_decode((string)$response->getBody(), true);
         $this->assertInternalType('array', $res);
 
         $this->assertSame($aArgs['title'], $res['title']);
@@ -119,25 +119,25 @@ class AttachmentControllerTest extends TestCase
         $attachmentController = new \Attachment\controllers\AttachmentController();
 
         //  DELETE
-        $environment    = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'DELETE']);
-        $request        = \Slim\Http\Request::createFromEnvironment($environment);
+        $environment  = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'DELETE']);
+        $request      = \Slim\Http\Request::createFromEnvironment($environment);
 
         $response     = $attachmentController->delete($request, new \Slim\Http\Response(), ['id' => self::$id]);
         $this->assertSame(204, $response->getStatusCode());
 
         //  DELETE
-        $environment    = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'DELETE']);
-        $request        = \Slim\Http\Request::createFromEnvironment($environment);
+        $environment  = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'DELETE']);
+        $request      = \Slim\Http\Request::createFromEnvironment($environment);
 
-        $response     = $attachmentController->delete($request, new \Slim\Http\Response(), ['id' => self::$id]);
-        $res = (array)json_decode((string)$response->getBody());
+        $response = $attachmentController->delete($request, new \Slim\Http\Response(), ['id' => self::$id]);
+        $res      = json_decode((string)$response->getBody(), true);
         $this->assertSame(400, $response->getStatusCode());
 
         $this->assertSame('Attachment does not exist', $res['errors']);
 
         //  READ
         $response = $attachmentController->getById($request, new \Slim\Http\Response(), ['id' => self::$id]);
-        $res = (array)json_decode((string)$response->getBody());
+        $res = json_decode((string)$response->getBody(), true);
         $this->assertSame(400, $response->getStatusCode());
 
         $this->assertSame('Attachment does not exist', $res['errors']);
-- 
GitLab