Completed
Push — master ( c68689...d67f41 )
by Adam
06:12
created

ReviewBoxController   A

Coupling/Cohesion

Components 1
Dependencies 11

Complexity

Total Complexity 6

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 11
dl 0
loc 60
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
B indexAction() 0 37 5
A reportAction() 0 19 1
1
<?php
2
/*
3
 * WellCommerce Open-Source E-Commerce Platform
4
 *
5
 * This file is part of the WellCommerce package.
6
 *
7
 * (c) Adam Piotrowski <[email protected]>
8
 *
9
 * For the full copyright and license information,
10
 * please view the LICENSE file that was distributed with this source code.
11
 */
12
13
namespace WellCommerce\Bundle\ReviewBundle\Controller\Box;
14
15
use Symfony\Component\HttpFoundation\Response;
16
use WellCommerce\Bundle\CoreBundle\Controller\Box\AbstractBoxController;
17
use WellCommerce\Bundle\ReviewBundle\Entity\Review;
18
use WellCommerce\Bundle\ReviewBundle\Repository\ReviewRepositoryInterface;
19
use WellCommerce\Component\Layout\Collection\LayoutBoxSettingsCollection;
20
21
22
/**
23
 * Class ReviewBoxController
24
 *
25
 * @author  Adam Piotrowski <[email protected]>
26
 */
27
class ReviewBoxController extends AbstractBoxController
28
{
29
    public function indexAction(LayoutBoxSettingsCollection $boxSettings): Response
30
    {
31
        /** @var ReviewRepositoryInterface $repository */
32
        $repository = $this->manager->getRepository();
33
        $product    = $this->getProductStorage()->getCurrentProduct();
34
        
35
        /** @var Review $resource */
36
        $resource = $this->getManager()->initResource();
37
        $resource->setProduct($product);
38
        
39
        $currentRoute = $product->translate()->getRoute()->getId();
0 ignored issues
show
Bug introduced by Adam Piotrowski
It seems like getRoute() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
40
        $form         = $this->formBuilder->createForm($resource);
41
        
42
        if ($form->handleRequest()->isSubmitted()) {
43
            if ($form->isValid()) {
44
                if (false === $this->get('security.authorization_checker')->isGranted('ROLE_CLIENT')
45
                    && false === $this->get('security.authorization_checker')->isGranted('ROLE_ADMIN')
46
                ) {
47
                    $resource->setEnabled(0);
0 ignored issues
show
Documentation introduced by Adam Piotrowski
0 is of type integer, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
48
                }
49
                $this->getManager()->createResource($resource);
50
                
51
                $this->getFlashHelper()->addSuccess('review.flash.success');
52
                
53
                return $this->getRouterHelper()->redirectTo('dynamic_' . $currentRoute);
54
            }
55
            
56
            $this->getFlashHelper()->addError('review.flash.error');
57
        }
58
        
59
        return $this->displayTemplate('index', [
60
            'form'        => $form,
61
            'product'     => $product,
62
            'reviews'     => $repository->getProductReviews($product),
63
            'boxSettings' => $boxSettings,
64
        ]);
65
    }
66
    
67
    public function reportAction(Review $review)
68
    {
69
        $currentRoute        = $review->getProduct()->translate()->getRoute()->getId();
0 ignored issues
show
Bug introduced by Adam Piotrowski
It seems like getRoute() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
70
        $mailerConfiguration = $this->getShopStorage()->getCurrentShop()->getMailerConfiguration();
71
        
72
        $this->getMailerHelper()->sendEmail([
73
            'recipient'     => $mailerConfiguration->getFrom(),
74
            'subject'       => $this->trans('review.email.heading.report'),
75
            'template'      => 'WellCommerceAppBundle:Email:report_review.html.twig',
76
            'parameters'    => [
77
                'review' => $review,
78
            ],
79
            'configuration' => $mailerConfiguration,
80
        ]);
81
        
82
        $this->getFlashHelper()->addSuccess('report.flash.success');
83
        
84
        return $this->redirectToRoute('dynamic_' . $currentRoute);
85
    }
86
}
87