AbstractDataCollector   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 70
Duplicated Lines 8.57 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 12
lcom 1
cbo 5
dl 6
loc 70
ccs 0
cts 17
cp 0
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getTemplate() 0 4 1
A setTemplate() 0 6 1
A setAdminRouteHelper() 0 4 1
B showDataCollection() 6 18 9

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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
Documentation introduced by
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
    /**
51
     * @param AdminRouteHelper $adminRouteHelper
52
     */
53
    public function setAdminRouteHelper(AdminRouteHelper $adminRouteHelper)
54
    {
55
        $this->adminRouteHelper = $adminRouteHelper;
56
    }
57
58
    /**
59
     * @param Request  $request
60
     * @param Response $response
61
     *
62
     * @return bool
63
     */
64
    public function showDataCollection(Request $request, Response $response)
65
    {
66
        $url = $request->getRequestUri();
67
68
        // do not capture redirects or modify XML HTTP Requests
69
        if ($request->isXmlHttpRequest() || $this->adminRouteHelper->isAdminRoute($url) || !$this->isEnabled()) {
70
            return false;
71
        }
72
73 View Code Duplication
        if ($response->isRedirection() || ($response->headers->has('Content-Type') && false === strpos($response->headers->get('Content-Type'), 'html'))
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
74
            || 'html' !== $request->getRequestFormat()
75
            || false !== stripos($response->headers->get('Content-Disposition'), 'attachment;')
76
        ) {
77
            return false;
78
        }
79
80
        return true;
81
    }
82
}
83