Completed
Push — master ( ae5e03...0447ee )
by Jeroen
10:35 queued 04:37
created

Controller/TagAdminListController.php (1 issue)

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