Web::show()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 7
Ratio 100 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 7
loc 7
ccs 4
cts 4
cp 1
rs 9.4286
cc 1
eloc 4
nc 1
nop 1
crap 1
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