Completed
Push — checkout-optimisation ( 4a6bfb...756f29 )
by Kamil
18:24
created

OrderController::completeAction()   C

Complexity

Conditions 11
Paths 13

Size

Total Lines 67
Code Lines 37

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 67
rs 5.8904
cc 11
eloc 37
nc 13
nop 1

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
/*
4
 * This file is part of the Sylius package.
5
 *
6
 * (c) Paweł Jędrzejewski
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Sylius\Bundle\CoreBundle\Controller;
13
14
use FOS\RestBundle\View\View;
15
use Sylius\Bundle\OrderBundle\Controller\OrderController as BaseOrderController;
16
use Symfony\Component\HttpFoundation\Request;
17
use Symfony\Component\HttpFoundation\Response;
18
use Webmozart\Assert\Assert;
19
20
class OrderController extends BaseOrderController
21
{
22
    /**
23
     * @param Request $request
24
     *
25
     * @return Response
26
     */
27
    public function thankYouAction(Request $request)
28
    {
29
        $configuration = $this->requestConfigurationFactory->create($this->metadata, $request);
30
31
        $orderId = $request->getSession()->get('sylius_order_id', null);
32
33
        if (null === $orderId) {
34
            $options = $configuration->getParameters()->get('after_failure');
35
36
            return $this->redirectHandler->redirectToRoute(
37
                $configuration,
38
                isset($options['route']) ? $options['route'] : 'sylius_shop_homepage',
39
                isset($options['parameters']) ? $options['parameters'] : []
40
            );
41
        }
42
43
        $request->getSession()->remove('sylius_order_id');
44
        $order = $this->repository->find($orderId);
45
        Assert::notNull($order);
46
47
        $view = View::create()
48
            ->setData([
49
                'order' => $order
50
            ])
51
            ->setTemplate($configuration->getParameters()->get('template'))
52
        ;
53
54
        return $this->viewHandler->handle($configuration, $view);
55
    }
56
}
57