TimelineFormatter   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
lcom 1
cbo 3
dl 0
loc 60
ccs 17
cts 17
cp 1
rs 10
c 1
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getProfilerDuration() 0 4 1
A __construct() 0 4 1
A getWidth() 0 5 1
A getOffset() 0 6 1
A getProfiler() 0 4 1
A setProfiler() 0 4 1
1
<?php
2
/**
3
 * @author @fabfuel <[email protected]>
4
 * @created 17.11.14, 07:45 
5
 */
6
namespace Fabfuel\Prophiler\Toolbar\Formatter;
7
8
use Fabfuel\Prophiler\ProfilerInterface;
9
10
class TimelineFormatter extends BenchmarkFormatterAbstract
11
{
12
    const TIMEBUFFER_FACTOR = 1.05;
13
14
    /**
15
     * @var ProfilerInterface
16
     */
17
    protected $profiler;
18
19
    /**
20
     * @param ProfilerInterface $profiler
21
     */
22 1
    public function __construct(ProfilerInterface $profiler)
23
    {
24 1
        $this->setProfiler($profiler);
25 1
    }
26
27
    /**
28
     * @return string
29
     */
30 1
    public function getWidth()
31
    {
32 1
        $widthPercentage = $this->getBenchmark()->getDuration() / $this->getProfilerDuration() * 100;
33 1
        return number_format($widthPercentage, 2, '.', '');
34
    }
35
36
    /**
37
     * @return string
38
     */
39 1
    public function getOffset()
40
    {
41 1
        $offset = ($this->getBenchmark()->getStartTime() - $this->getProfiler()->getStartTime()) * 1000;
42 1
        $offsetPercentage = $offset / $this->getProfilerDuration() * 100;
43 1
        return number_format($offsetPercentage, 2, '.', '');
44
    }
45
46
    /**
47
     * @return ProfilerInterface
48
     */
49 1
    public function getProfiler()
50
    {
51 1
        return $this->profiler;
52
    }
53
54
    /**
55
     * @param ProfilerInterface $profiler
56
     */
57 1
    public function setProfiler(ProfilerInterface $profiler)
58
    {
59 1
        $this->profiler = $profiler;
60 1
    }
61
62
    /**
63
     * @return float
64
     */
65 2
    protected function getProfilerDuration()
66
    {
67 2
        return $this->getProfiler()->getDuration() * self::TIMEBUFFER_FACTOR;
68
    }
69
}
70