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

AdminBundle/Toolbar/ExceptionDataCollector.php (1 issue)

Checks whether return doc types can be made more specific.

Documentation Informational

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;
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