Completed
Push — master ( 1de9b7...830752 )
by Kristof
38:46 queued 24:09
created

AdminBundle/Toolbar/ExceptionDataCollector.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\AdminBundle\Toolbar;
4
5
use Doctrine\ORM\EntityManagerInterface;
6
use Kunstmaan\AdminBundle\Entity\Exception;
7
use Kunstmaan\AdminBundle\Helper\Toolbar\AbstractDataCollector;
8
use Symfony\Component\HttpFoundation\Request;
9
use Symfony\Component\HttpFoundation\Response;
10
11
class ExceptionDataCollector extends AbstractDataCollector
12
{
13
    /**
14
     * @var EntityManagerInterface
15
     */
16
    private $em;
17
18
    public function __construct(EntityManagerInterface $em)
19
    {
20
        $this->em = $em;
21
    }
22
23
    /**
24
     * @return array
0 ignored issues
show
Consider making the return type a bit more specific; maybe use string[].

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
25
     */
26
    public function getAccessRoles()
27
    {
28
        return ['ROLE_ADMIN'];
29
    }
30
31
    /**
32
     * @return array
33
     */
34
    public function collectData()
35
    {
36
        $model = $this->em->getRepository(Exception::class)->findExceptionStatistics();
37
        if (isset($model['cp_all'], $model['cp_sum'])) {
38
            return [
39
                'data' => $model,
40
            ];
41
        } else {
42
            return [];
43
        }
44
    }
45
46
    /**
47
     * @param Request         $request
48
     * @param Response        $response
49
     * @param \Exception|null $exception
50
     */
51
    public function collect(Request $request, Response $response, \Exception $exception = null)
52
    {
53
        if (false === $this->isEnabled()) {
54
            $this->data = false;
0 ignored issues
show
Documentation Bug introduced by
It seems like false of type false is incompatible with the declared type array of property $data.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
55
        } else {
56
            $this->data = $this->collectData();
57
        }
58
    }
59
60
    /**
61
     * Gets the data for template
62
     *
63
     * @return array The request events
64
     */
65
    public function getTemplateData()
66
    {
67
        return $this->data;
68
    }
69
70
    /**
71
     * @return string
72
     */
73
    public function getName()
74
    {
75
        return 'kuma_exception';
76
    }
77
78
    /**
79
     * @return bool
80
     */
81
    public function isEnabled()
82
    {
83
        return true;
84
    }
85
86
    public function reset()
87
    {
88
        $this->data = [];
89
    }
90
}
91