TakeCustomerAccountController   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 9
c 2
b 0
f 0
lcom 0
cbo 1
dl 0
loc 58
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
C takeAction() 0 50 9
1
<?php
2
/*************************************************************************************/
3
/*      This file is part of the module TakeCustomerAccount                          */
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 TakeCustomerAccount\Controller;
14
15
use TakeCustomerAccount\Event\TakeCustomerAccountEvent;
16
use TakeCustomerAccount\Event\TakeCustomerAccountEvents;
17
use TakeCustomerAccount\TakeCustomerAccount;
18
use Thelia\Controller\Admin\BaseAdminController;
19
use Thelia\Core\HttpKernel\Exception\RedirectException;
20
use Thelia\Core\Security\AccessManager;
21
use Thelia\Model\CustomerQuery;
22
23
/**
24
 * Class TakeCustomerAccountController
25
 * @package TakeCustomerAccount\Controller
26
 * @author Gilles Bourgeat <[email protected]>
27
 */
28
class TakeCustomerAccountController extends BaseAdminController
29
{
30
    /**
31
     * @param int $customer_id
32
     * @return \Symfony\Component\HttpFoundation\Response
33
     * @throws \Exception
34
     */
35
    public function takeAction($customer_id)
36
    {
37
        if (null !== $response = $this->checkAuth(array(), 'TakeCustomerAccount', AccessManager::VIEW)) {
38
            return $response;
39
        }
40
41
        $form = $this->createForm('take_customer_account');
42
43
        try {
44
            if (null !== $customer = CustomerQuery::create()->findPk($customer_id)) {
45
                $this->validateForm($form);
46
47
                $this->dispatch(
48
                    TakeCustomerAccountEvents::TAKE_CUSTOMER_ACCOUNT,
49
                    new TakeCustomerAccountEvent($customer)
50
                );
51
            } else {
52
                throw new \Exception($this->getTranslator()->trans(
53
                    "Customer not found",
54
                    [],
55
                    TakeCustomerAccount::MODULE_DOMAIN
56
                ));
57
            }
58
59
            // since version 1.2.0, use method_exists for retro compatibility
60
            if (method_exists($form, 'hasSuccessUrl') && $form->hasSuccessUrl()) {
61
                return $this->generateRedirectFromRoute($form->getSuccessUrl());
62
            }
63
64
            $this->setCurrentRouter('router.front');
65
            return $this->generateRedirectFromRoute('customer.home', [], [], 'router.front');
66
        } catch (RedirectException $e) {
0 ignored issues
show
Bug introduced by
The class Thelia\Core\HttpKernel\Exception\RedirectException 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...
67
            return $this->generateRedirect($e->getUrl(), $e->getCode());
68
        } catch (\Exception $e) {
69
            // since version 1.2.0, use method_exists for retro compatibility
70
            if (method_exists($form, 'hasErrorUrl') && $form->hasErrorUrl()) {
71
                return $this->generateRedirect($form->getErrorUrl());
72
            }
73
74
            $form->setErrorMessage($e->getMessage());
75
76
            $this->getParserContext()->addForm($form);
77
78
            $this->setCurrentRouter('router.admin');
79
            return $this->generateRedirectFromRoute(
80
                'admin.customer.update.view',
81
                ['customer_id' => $customer_id]
82
            );
83
        }
84
    }
85
}
86