Timeline::getData()   C
last analyzed

Complexity

Conditions 13
Paths 85

Size

Total Lines 43
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 26
CRAP Score 13.4003

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 0
loc 43
ccs 26
cts 30
cp 0.8667
rs 5.1234
cc 13
eloc 22
nc 85
nop 0
crap 13.4003

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: arnaud
5
 * Date: 22/11/15
6
 * Time: 19:01
7
 */
8
9
namespace Ndrx\Profiler\Renderer\Html\Data;
10
11
use Ndrx\Profiler\Renderer\Html\PageInterface;
12
13
class Timeline extends Collector implements PageInterface
14
{
15
    /**
16
     * @return string
17
     */
18 10
    public function getTitle()
19
    {
20 10
        return 'Timeline';
21
    }
22
23
24 10
    public function getData()
25
    {
26 10
        $data = $this->profile;
27
28 10
        if (!array_key_exists('value', $data) || !is_array($data['value'])) {
29 6
            return [];
30
        }
31
32 4
        $min = false;
33 4
        $max = false;
34
35 4
        foreach ($data['value'] as $key => $item) {
36 2
            if (is_bool($min) || $item['start'] < $min) {
37 2
                $min = $item['start'];
38 2
            }
39
40 2
            if (array_key_exists('end', $item)) {
41 2
                if (is_bool($max) || $item['end'] > $max) {
42 2
                    $max = $item['end'];
43 2
                }
44 2
            }
45 4
        }
46
47 4
        if ($min === 0) {
48 2
            $min = 1;
49 2
        }
50
51
52 4
        if ($max === 0) {
53
            $max = 1;
54
        }
55
56
57 4
        foreach ($data['value'] as $key => $item) {
58 2
            if (!array_key_exists('end', $item)) {
59
                $item['end'] = $max;
60
            }
61 2
            $data['value'][$key]['offset'] = floor((($item['start'] - $min) / $min) * 100);
62 2
            $data['value'][$key]['length'] = floor((($item['end'] - $item['start']) / ($max - $min)) * 100);
63 4
        }
64
65 4
        return $data;
66
    }
67
68 10
    public function getIcon()
69
    {
70 10
        return 'fa-play';
71
    }
72
}
73