Duration::getPath()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: arnaud
5
 * Date: 01/11/15
6
 * Time: 20:43
7
 */
8
9
namespace Ndrx\Profiler\Collectors\Data;
10
11
use Ndrx\Profiler\Collectors\Collector;
12
use Ndrx\Profiler\Collectors\Contracts\FinalCollectorInterface;
13
use Ndrx\Profiler\DataSources\Contracts\DataSourceInterface;
14
use Ndrx\Profiler\JsonPatch;
15
use Ndrx\Profiler\Process;
16
use Ndrx\Profiler\Renderer\BarRenderableInterface;
17
18
class Duration extends Collector implements FinalCollectorInterface, BarRenderableInterface
19
{
20
    protected $start;
21
    /**
22
     * EventsDataSource constructor.
23
     */
24 18
    public function __construct(Process $process, DataSourceInterface $dataSource, JsonPatch $jsonPatch = null)
25
    {
26 18
        $this->start = microtime(true);
27
28 18
        parent::__construct($process, $dataSource, $jsonPatch);
29 18
    }
30
31 6
    public function validate()
32
    {
33 6 View Code Duplication
        if (!is_numeric($this->data)) {
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...
34
            throw new \LogicException('Duration must be a number ' . json_encode($this->data) . ' given');
35
        }
36 6
    }
37
38
    /**
39
     * Fetch data
40
     * @return mixed
41
     */
42 8
    public function resolve()
43
    {
44 8
        $end = microtime(true);
45
46 8
        $this->data = $end - $this->start;
47 8
    }
48
49
    /**
50
     * The path in the final json
51
     * @example
52
     *  path /aa/bb
53
     *  will be transformed to
54
     *  {
55
     *     aa : {
56
     *              bb: <VALUE OF RESOLVE>
57
     *       }
58
     *  }
59
     * @return string
60
     */
61 16
    public function getPath()
62
    {
63 16
        return 'duration';
64
    }
65
}
66