Completed
Pull Request — master (#13)
by zzuutt
02:32
created

ConfigureController::configureAction()   B

Complexity

Conditions 6
Paths 27

Size

Total Lines 48
Code Lines 27

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 48
rs 8.551
cc 6
eloc 27
nc 27
nop 0
1
<?php
2
/*************************************************************************************/
3
/*      This file is part of the Thelia package.                                     */
4
/*                                                                                   */
5
/*      Copyright (c) OpenStudio                                                     */
6
/*      email : [email protected]                                                       */
7
/*      web : http://www.thelia.net                                                  */
8
/*                                                                                   */
9
/*      For the full copyright and license information, please view the LICENSE.txt  */
10
/*      file that was distributed with this source code.                             */
11
/*************************************************************************************/
12
13
namespace Dealer\Controller;
14
15
use Dealer\Dealer;
16
use Symfony\Component\Filesystem\Filesystem;
17
use Symfony\Component\HttpFoundation\Response;
18
use Thelia\Controller\Admin\BaseAdminController;
19
use Thelia\Core\Security\AccessManager;
20
use Thelia\Core\Security\Resource\AdminResources;
21
use Thelia\Core\Thelia;
22
use Thelia\Form\Exception\FormValidationException;
23
use Thelia\Tools\URL;
24
use Thelia\Tools\Version\Version;
25
26
/**
27
 * Class ConfigureController
28
 * @package DealerGoogleTimeZone\Controller
29
 */
30
class ConfigureController extends BaseAdminController
31
{
32
33
    public function configureAction()
34
    {
35
        if (null !== $response = $this->checkAuth(AdminResources::MODULE, 'dealer', AccessManager::UPDATE)) {
36
            return $response;
37
        }
38
39
        $configurationForm = $this->createForm('dealer.configuration.form');
40
        $message = null;
0 ignored issues
show
Unused Code introduced by
$message is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
41
42
        try {
43
            $form = $this->validateForm($configurationForm);
44
45
            // Get the form field values
46
            $data = $form->getData();
47
48
            Dealer::setConfigValue('googlemapsapi_key',$data['googlemapsapi_key']);
49
50
51
            // Redirect to the success URL,
52
            if ($this->getRequest()->get('save_mode') == 'stay') {
53
                // If we have to stay on the same page, redisplay the configuration page/
54
                $url = '/admin/module/Dealer';
55
            } else {
56
                // If we have to close the page, go back to the module back-office page.
57
                $url = '/admin/modules';
58
            }
59
60
            return $this->generateRedirect(URL::getInstance()->absoluteUrl($url));
61
        } catch (FormValidationException $ex) {
0 ignored issues
show
Bug introduced by
The class Thelia\Form\Exception\FormValidationException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
62
            $message = $this->createStandardFormValidationErrorMessage($ex);
63
        } catch (\Exception $ex) {
64
            $message = $ex->getMessage();
65
        }
66
67
        $this->setupFormErrorContext(
68
            $this->getTranslator()->trans("Dealer configuration", [], Dealer::MESSAGE_DOMAIN),
69
            $message,
70
            $configurationForm,
71
            $ex
72
        );
73
74
        // Before 2.2, the errored form is not stored in session
75
        if (Version::test(Thelia::THELIA_VERSION, '2.2', false, "<")) {
76
            return $this->render('module-configure', [ 'module_code' => 'Dealer' ]);
77
        } else {
78
            return $this->generateRedirect(URL::getInstance()->absoluteUrl('/admin/module/Dealer'));
79
        }
80
    }
81
}
82