Completed
Pull Request — master (#2094)
by Sander
50:34 queued 34:10
created

Controller/TagAdminListController.php (2 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\TaggingBundle\Controller;
4
5
use Kunstmaan\AdminListBundle\AdminList\Configurator\AdminListConfiguratorInterface;
6
use Kunstmaan\AdminListBundle\Controller\AdminListController;
7
use Kunstmaan\TaggingBundle\AdminList\TagAdminListConfigurator;
8
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
9
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
10
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
11
use Symfony\Component\HttpFoundation\Request;
12
13
class TagAdminListController extends AdminListController
14
{
15
    /**
16
     * @var AdminListConfiguratorInterface
17
     */
18
    private $configurator;
19
20
    /**
21
     * @return AdminListConfiguratorInterface
22
     */
23
    public function getAdminListConfigurator()
24
    {
25
        if (!isset($this->configurator)) {
26
            $this->configurator = new TagAdminListConfigurator($this->getEntityManager());
27
        }
28
29
        return $this->configurator;
30
    }
31
32
    /**
33
     * @Route("/", name="kunstmaantaggingbundle_admin_tag")
34
     * @Template("KunstmaanAdminListBundle:Default:list.html.twig")
35
     */
36
    public function indexAction(Request $request)
37
    {
38
        return parent::doIndexAction($this->getAdminListConfigurator(), $request);
39
    }
40
41
    /**
42
     * @Route("/add", name="kunstmaantaggingbundle_admin_tag_add")
43
     * @Method({"GET", "POST"})
44
     * @Template("KunstmaanAdminListBundle:Default:add.html.twig")
45
     * @return array
46
     */
47
    public function addAction(Request $request)
48
    {
49
        return parent::doAddAction($this->getAdminListConfigurator(), null, $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 (doAddAction() instead of addAction()). Are you sure this is correct? If so, you might want to change this to $this->doAddAction().

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...
50
    }
51
52
    /**
53
     * @Route("/{id}/edit", requirements={"id" = "\d+"}, name="kunstmaantaggingbundle_admin_tag_edit")
54
     * @Method({"GET", "POST"})
55
     * @Template("KunstmaanAdminListBundle:Default:edit.html.twig")
56
     */
57
    public function editAction(Request $request, $id)
58
    {
59
        return parent::doEditAction($this->getAdminListConfigurator(), $id, $request);
60
    }
61
62
    /**
63
     * @Route("/{id}/delete", requirements={"id" = "\d+"}, name="kunstmaantaggingbundle_admin_tag_delete")
64
     * @Method({"GET", "POST"})
65
     * @Template("KunstmaanAdminListBundle:Default:delete.html.twig")
66
     */
67
    public function deleteAction(Request $request, $id)
68
    {
69
        return parent::doDeleteAction($this->getAdminListConfigurator(), $id, $request);
70
    }
71
72
    /**
73
     * @Route("/autocomplete.{_format}", name="kunstmaantaggingbundle_admin_tag_autocomplete", defaults={"_format" = "json"})
74
     * @Template()
75
     *
76
     * @param \Symfony\Component\HttpFoundation\Request $request
77
     *
78
     * @return array
79
     */
80
    public function autocompleteAction(Request $request)
81
    {
82
        $search = $request->get('term');
83
        $em = $this->getDoctrine()->getManager();
84
        $qb = $em->getRepository('KunstmaanTaggingBundle:Tag')->createQueryBuilder('n')
85
            ->where('n.name LIKE :search')
86
            ->orderBy('n.name', 'ASC')
87
            ->setParameter('search', '%' . $search . '%');
88
        $tags = $qb->getQuery()->getResult();
89
90
        return array('tags' => $tags);
91
    }
92
}
93