Completed
Pull Request — 5.6 (#2830)
by Jeroen
14:14
created

AdminBundle/Controller/ExceptionController.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\AdminBundle\Controller;
4
5
use Doctrine\ORM\EntityManager;
6
use Kunstmaan\AdminBundle\AdminList\ExceptionAdminListConfigurator;
7
use Kunstmaan\AdminBundle\Entity\Exception;
8
use Kunstmaan\AdminListBundle\Controller\AdminListController;
9
use Symfony\Component\HttpFoundation\RedirectResponse;
10
use Symfony\Component\HttpFoundation\Request;
11
use Symfony\Component\Routing\Annotation\Route;
12
13
class ExceptionController extends AdminListController
14
{
15
    /** @var ExceptionAdminListConfigurator */
16
    private $configurator;
17
18
    private function getAdminListConfigurator()
19
    {
20
        if (!isset($this->configurator)) {
21
            $this->configurator = new ExceptionAdminListConfigurator($this->getEntityManager());
22
        }
23
24
        return $this->configurator;
25
    }
26
27
    /**
28
     * @Route("/", name="kunstmaanadminbundle_admin_exception")
29
     */
30
    public function indexAction(Request $request)
31
    {
32
        return parent::doIndexAction($this->getAdminListConfigurator(), $request);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (doIndexAction() instead of indexAction()). Are you sure this is correct? If so, you might want to change this to $this->doIndexAction().

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...
33
    }
34
35
    /**
36
     * @Route("/resolve_all", name="kunstmaanadminbundle_admin_exception_resolve_all")
37
     *
38
     * @return RedirectResponse
39
     *
40
     * @throws \Doctrine\ORM\NonUniqueResultException
41
     * @throws \Doctrine\ORM\NoResultException
42
     * @throws \InvalidArgumentException
43
     */
44
    public function resolveAllAction()
45
    {
46
        $this->getEntityManager()->getRepository(Exception::class)->markAllAsResolved();
47
48
        $indexUrl = $this->getAdminListConfigurator()->getIndexUrl();
49
50
        return new RedirectResponse(
51
            $this->generateUrl(
52
                $indexUrl['path'],
53
                isset($indexUrl['params']) ? $indexUrl['params'] : []
54
            )
55
        );
56
    }
57
58
    /**
59
     * @Route("/toggle_resolve/{id}", name="kunstmaanadminbundle_admin_exception_toggle_resolve")
60
     *
61
     * @return RedirectResponse
62
     *
63
     * @throws \Doctrine\ORM\OptimisticLockException
64
     * @throws \InvalidArgumentException
65
     * @throws \Doctrine\ORM\ORMInvalidArgumentException
66
     */
67
    public function toggleResolveAction(Request $request, Exception $model)
68
    {
69
        /* @var EntityManager $em */
70
        $em = $this->getEntityManager();
71
72
        $this->getAdminListConfigurator();
73
74
        $model->setResolved(!$model->isResolved());
75
76
        $em->persist($model);
77
        $em->flush();
78
79
        $indexUrl = $this->configurator->getIndexUrl();
80
81
        return new RedirectResponse(
82
            $this->generateUrl(
83
                $indexUrl['path'],
84
                isset($indexUrl['params']) ? $indexUrl['params'] : []
85
            )
86
        );
87
    }
88
}
89