Completed
Push — master ( 6c15b7...f5f8be )
by Sander
12:00
created

Controller/PopupsAdminListController.php (7 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace Kunstmaan\LeadGenerationBundle\Controller;
4
5
use Kunstmaan\AdminBundle\Entity\EntityInterface;
6
use Kunstmaan\AdminListBundle\AdminList\Configurator\AdminListConfiguratorInterface;
7
use Kunstmaan\AdminListBundle\AdminList\ItemAction\SimpleItemAction;
8
use Kunstmaan\AdminListBundle\Controller\AdminListController;
9
use Kunstmaan\LeadGenerationBundle\AdminList\PopupAdminListConfigurator;
10
use Symfony\Component\Routing\Annotation\Route;
11
use Symfony\Component\HttpFoundation\Request;
12
13
class PopupsAdminListController extends AdminListController
14
{
15
    /**
16
     * @var AdminListConfiguratorInterface
17
     */
18
    private $configurator;
19
20
    /**
21
     * @return AdminListConfiguratorInterface
22
     */
23
    public function getAdminListConfigurator($listAction = false)
24
    {
25
        if (!isset($this->configurator)) {
26
            $this->configurator = new PopupAdminListConfigurator($this->getEntityManager());
27
28
            if ($listAction) {
29
                $create_route = function (EntityInterface $item) {
30
                    return array(
31
                        'path' => 'kunstmaanleadgenerationbundle_admin_rule_abstractrule_detail',
32
                        'params' => array('popup' => $item->getId()),
33
                    );
34
                };
35
                $this->configurator->addItemAction(new SimpleItemAction($create_route, 'th-list', 'Manage rules'));
36
            }
37
        }
38
39
        return $this->configurator;
40
    }
41
42
    /**
43
     * The index action
44
     *
45
     * @Route("/", name="kunstmaanleadgenerationbundle_admin_popup_abstractpopup")
46
     */
47
    public function indexAction(Request $request)
48
    {
49
        return parent::doIndexAction($this->getAdminListConfigurator(true), $request);
50
    }
51
52
    /**
53
     * The delete action
54
     *
55
     * @param int $id
56
     *
57
     * @Route("/{id}/delete", requirements={"id" = "\d+"}, name="kunstmaanleadgenerationbundle_admin_popup_abstractpopup_delete", methods={"GET", "POST"})
58
     *
59
     * @return array
0 ignored issues
show
Should the return type not be \Symfony\Component\HttpFoundation\Response?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
60
     */
61
    public function deleteAction(Request $request, $id)
62
    {
63
        return parent::doDeleteAction($this->getAdminListConfigurator(), $id, $request);
0 ignored issues
show
$this->getAdminListConfigurator() of type object<Kunstmaan\AdminLi...tConfiguratorInterface> is not a sub-type of object<Kunstmaan\AdminLi...tAdminListConfigurator>. It seems like you assume a concrete implementation of the interface Kunstmaan\AdminListBundl...stConfiguratorInterface to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
Comprehensibility Bug introduced by
It seems like you call parent on a different method (doDeleteAction() instead of deleteAction()). Are you sure this is correct? If so, you might want to change this to $this->doDeleteAction().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
64
    }
65
66
    /**
67
     * The edit action
68
     *
69
     * @param int $id
70
     *
71
     * @Route("/{id}/edit", requirements={"id" = "\d+"}, name="kunstmaanleadgenerationbundle_admin_popup_abstractpopup_edit", methods={"GET", "POST"})
72
     *
73
     * @return array
0 ignored issues
show
Should the return type not be \Symfony\Component\HttpFoundation\Response?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
74
     */
75
    public function editAction(Request $request, $id)
76
    {
77
        return parent::doEditAction($this->getAdminListConfigurator(), $id, $request);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (doEditAction() instead of editAction()). Are you sure this is correct? If so, you might want to change this to $this->doEditAction().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
78
    }
79
80
    /**
81
     * The add action
82
     *
83
     * @Route("/add",  name="kunstmaanleadgenerationbundle_admin_popup_abstractpopup_add", methods={"GET", "POST"})
84
     *
85
     * @return array
0 ignored issues
show
Should the return type not be \Symfony\Component\HttpFoundation\Response?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
86
     */
87
    public function addAction(Request $request)
88
    {
89
        $type = $request->get('type');
90
91
        return parent::doAddAction($this->getAdminListConfigurator(), $type, $request);
0 ignored issues
show
$this->getAdminListConfigurator() of type object<Kunstmaan\AdminLi...tConfiguratorInterface> is not a sub-type of object<Kunstmaan\AdminLi...tAdminListConfigurator>. It seems like you assume a concrete implementation of the interface Kunstmaan\AdminListBundl...stConfiguratorInterface to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
92
    }
93
}
94