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

Helper/Toolbar/AbstractDataCollector.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\Helper\Toolbar;
4
5
use Kunstmaan\AdminBundle\Helper\AdminRouteHelper;
6
use Symfony\Component\HttpFoundation\Request;
7
use Symfony\Component\HttpFoundation\Response;
8
use Symfony\Component\HttpKernel\DataCollector\DataCollector as BaseDataCollector;
9
10
/**
11
 * AbstractDataCollector.
12
 */
13
abstract class AbstractDataCollector extends BaseDataCollector implements DataCollectionInterface
14
{
15
    /**
16
     * @var array
17
     */
18
    protected $data = [];
19
20
    /**
21
     * @var string
22
     */
23
    private $template;
24
25
    /**
26
     * @var AdminRouteHelper
27
     */
28
    protected $adminRouteHelper;
29
30
    /**
31
     * @return mixed
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...
32
     */
33
    public function getTemplate()
34
    {
35
        return $this->template;
36
    }
37
38
    /**
39
     * @param $template
40
     *
41
     * @return $this
42
     */
43
    public function setTemplate($template)
44
    {
45
        $this->template = $template;
46
47
        return $this;
48
    }
49
50
    public function setAdminRouteHelper(AdminRouteHelper $adminRouteHelper)
51
    {
52
        $this->adminRouteHelper = $adminRouteHelper;
53
    }
54
55
    /**
56
     * @return bool
57
     */
58
    public function showDataCollection(Request $request, Response $response)
59
    {
60
        $url = $request->getRequestUri();
61
62
        // do not capture redirects or modify XML HTTP Requests
63
        if ($request->isXmlHttpRequest() || $this->adminRouteHelper->isAdminRoute($url) || !$this->isEnabled()) {
64
            return false;
65
        }
66
67 View Code Duplication
        if ($response->isRedirection() || ($response->headers->has('Content-Type') && false === strpos($response->headers->get('Content-Type'), 'html'))
68
            || 'html' !== $request->getRequestFormat()
69
            || false !== stripos($response->headers->get('Content-Disposition'), 'attachment;')
70
        ) {
71
            return false;
72
        }
73
74
        return true;
75
    }
76
}
77