Duration   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 48
Duplicated Lines 6.25 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 92.86%

Importance

Changes 3
Bugs 0 Features 1
Metric Value
wmc 5
c 3
b 0
f 1
lcom 1
cbo 1
dl 3
loc 48
ccs 13
cts 14
cp 0.9286
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A validate() 3 6 2
A resolve() 0 6 1
A getPath() 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: 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