Timeline::getTitle()   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 0
Metric Value
c 1
b 0
f 0
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: 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