Web   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 65
Duplicated Lines 36.92 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 95.65%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 7
c 3
b 0
f 0
lcom 1
cbo 4
dl 24
loc 65
ccs 22
cts 23
cp 0.9565
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A index() 0 7 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\Process;
7
use Ndrx\Profiler\Renderer\Html\ProcessList;
8
9
/**
10
 * Created by PhpStorm.
11
 * User: arnaud
12
 * Date: 21/11/15
13
 * Time: 17:16
14
 */
15
class Web
16
{
17
18
    /**
19
     * @var ProfilerInterface
20
     */
21
    protected $profiler;
22
23
    /**
24
     * Web constructor.
25
     * @param ProfilerInterface $profiler
26
     */
27 6
    public function __construct(ProfilerInterface $profiler)
28
    {
29 6
        $this->profiler = $profiler;
30 6
    }
31
32
33
    /**
34
     * @param int $offset
35
     * @param int $limit
36
     * @return string
37
     */
38 2
    public function index($offset = 0, $limit = 20)
39
    {
40 2
        $profiles = $this->profiler->getDatasource()->all($offset, $limit);
41 2
        $renderer = new ProcessList($profiles);
42
43 2
        return $renderer->content();
44
    }
45
46
    /**
47
     * @param $id
48
     * @return string
49
     */
50 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...
51
    {
52 4
        $profile = $this->objectToArray($this->profiler->getProfile($id));
53 4
        $renderer = new Process($profile, $this->profiler);
54
55 4
        return $renderer->content();
56
    }
57
58
    /**
59
     * @param $obj
60
     * @return array
61
     */
62 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...
63
    {
64 4
        if (is_object($obj)) {
65 4
            $obj = (array)$obj;
66 4
        }
67
68 4
        if (is_array($obj)) {
69 4
            $new = array();
70 4
            foreach ($obj as $key => $val) {
71 2
                $new[$key] = $this->objectToArray($val);
72 4
            }
73 4
        } else {
74
            $new = $obj;
75
        }
76
77 4
        return $new;
78
    }
79
}
80