Timer   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 2
dl 0
loc 35
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A start() 0 6 1
A stop() 0 11 3
A getTime() 0 4 1
1
<?php
2
3
/*
4
 * This file is part of the Ivory Http Adapter package.
5
 *
6
 * (c) Eric GELOEN <[email protected]>
7
 *
8
 * For the full copyright and license information, please read the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Ivory\HttpAdapter\Event\Timer;
13
14
use Ivory\HttpAdapter\Message\InternalRequestInterface;
15
16
/**
17
 * @author GeLo <[email protected]>
18
 */
19
class Timer implements TimerInterface
20
{
21
    /**
22
     * {@inheritdoc}
23
     */
24 9
    public function start(InternalRequestInterface $internalRequest)
25
    {
26
        return $internalRequest
27 9
            ->withParameter(self::START_TIME, $this->getTime())
28 9
            ->withoutParameter(self::TIME);
29
    }
30
31
    /**
32
     * {@inheritdoc}
33
     */
34 18
    public function stop(InternalRequestInterface $internalRequest)
35
    {
36 18
        if ($internalRequest->hasParameter(self::START_TIME) && !$internalRequest->hasParameter(self::TIME)) {
37 9
            return $internalRequest->withParameter(
38 9
                self::TIME,
39 9
                $this->getTime() - $internalRequest->getParameter(self::START_TIME)
40 7
            );
41
        }
42
43 9
        return $internalRequest;
44
    }
45
46
    /**
47
     * @return float
48
     */
49 18
    private function getTime()
50
    {
51 18
        return microtime(true);
52
    }
53
}
54