Bar   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 52
Duplicated Lines 46.15 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 94.74%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 6
c 3
b 0
f 0
lcom 1
cbo 2
dl 24
loc 52
ccs 18
cts 19
cp 0.9474
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A show() 7 7 1
A objectToArray() 17 17 4

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 Ndrx\Profiler\Controllers;
4
5
use Ndrx\Profiler\ProfilerInterface;
6
use Ndrx\Profiler\Renderer\Html\Bar as BarRenderer;
7
8
/**
9
 * Created by PhpStorm.
10
 * User: arnaud
11
 * Date: 21/11/15
12
 * Time: 17:16
13
 */
14
class Bar
15
{
16
17
    /**
18
     * @var ProfilerInterface
19
     */
20
    protected $profiler;
21
22
    /**
23
     * Web constructor.
24
     * @param ProfilerInterface $profiler
25
     */
26 4
    public function __construct(ProfilerInterface $profiler)
27
    {
28 4
        $this->profiler = $profiler;
29 4
    }
30
31
32
    /**
33
     * @param $id
34
     * @return string
35
     */
36 4 View Code Duplication
    public function show($id)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
37
    {
38 4
        $profile = $this->objectToArray($this->profiler->getProfile($id));
39 4
        $renderer = new BarRenderer($profile, $this->profiler);
40
41 4
        return $renderer->content();
42
    }
43
44
    /**
45
     * @param $obj
46
     * @return array
47
     */
48 4 View Code Duplication
    protected function objectToArray($obj)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
49
    {
50 4
        if (is_object($obj)) {
51 4
            $obj = (array)$obj;
52 4
        }
53
54 4
        if (is_array($obj)) {
55 4
            $new = array();
56 4
            foreach ($obj as $key => $val) {
57 2
                $new[$key] = $this->objectToArray($val);
58 4
            }
59 4
        } else {
60
            $new = $obj;
61
        }
62
63 4
        return $new;
64
    }
65
}
66