Bar   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 84
Duplicated Lines 3.57 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 4
Bugs 0 Features 1
Metric Value
wmc 9
c 4
b 0
f 1
lcom 1
cbo 5
dl 3
loc 84
ccs 37
cts 37
cp 1
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getTemplate() 0 4 1
B getData() 3 38 5
A getIcon() 0 4 1
A getTitle() 0 4 1

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
 * Created by PhpStorm.
4
 * User: arnaud
5
 * Date: 21/11/15
6
 * Time: 15:14
7
 */
8
9
namespace Ndrx\Profiler\Renderer\Html;
10
11
use Ndrx\Profiler\ProfilerInterface;
12
use Ndrx\Profiler\Renderer\RenderableInterface;
13
use Symfony\Component\HttpFoundation\Request;
14
15
class Bar extends Renderer
16
{
17
    /**
18
     * @var ProfilerInterface
19
     */
20
    protected $profiler;
21
22
    /**
23
     * Process constructor.
24
     */
25 16
    public function __construct(array $profile, ProfilerInterface $profiler)
26 2
    {
27 16
        $this->profiler = $profiler;
28
29 16
        parent::__construct($profile);
30 16
    }
31
32
33
    /**
34
     * @return mixed
35
     */
36 16
    public function getTemplate()
37
    {
38 16
        return 'bar.html.twig';
39
    }
40
41
    /**
42
     * @return mixed
43
     */
44 16
    public function getData()
45
    {
46 16
        $collectors = [];
47
48 16
        $dataCollectors = $this->profiler->getCollectors();
49 16
        $dataCollectors = call_user_func_array('array_merge', $dataCollectors);
50 16
        foreach ($dataCollectors as $collector) {
51 16
            if ($collector instanceof RenderableInterface) {
52 16
                $renderer = $collector->getRenderer();
53 16
                if ($renderer instanceof BarInterface) {
54
                    $data = [
55
                        'value' => null
56 16
                    ];
57
58 16 View Code Duplication
                    if (array_key_exists($collector->getPath(), $this->profile)) {
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...
59 8
                        $data['value'] = $this->profile[$collector->getPath()];
60 8
                    }
61 16
                    $renderer->setData($data);
62
63
                    $data = [
64 16
                        'icon' => $renderer->getIcon(),
65 16
                        'badge' => $renderer->getBadge(),
66 16
                        'content' => $renderer->getBarContent(),
67 16
                        'title' => $renderer->getTitle()
68 16
                    ];
69
70 16
                    $collectors[$collector->getName()] = $data;
71 16
                }
72 16
            }
73 16
        }
74
75 16
        $currenturl = Request::createFromGlobals()->getUri();
76
77
        return [
78 16
            'collectors' => $collectors,
79 16
            'profileUrl' => str_replace('bar/', '', $currenturl)
80 16
        ];
81
    }
82
83
    /**
84
     * @return string
85
     */
86 16
    public function getIcon()
87
    {
88 16
        return 'options';
89
    }
90
91
    /**
92
     * @return string
93
     */
94 16
    public function getTitle()
95
    {
96 16
        return 'Bar';
97
    }
98
}
99