ApiDataCollector::getCalls()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 3
c 0
b 0
f 0
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 1
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Nixilla\Api\LoggerBundle\DataCollector;
4
5
use Nixilla\Api\LoggerBundle\Logger\ApiInterface;
6
use Symfony\Component\HttpFoundation\Request;
7
use Symfony\Component\HttpFoundation\Response;
8
use Symfony\Component\HttpKernel\DataCollector\DataCollector;
9
10
class ApiDataCollector extends DataCollector
11
{
12
    /**
13
     * @var \Nixilla\Api\LoggerBundle\Logger\ApiInterface
14
     */
15
    protected $logger;
16
17
    /**
18
     * {@inheritDoc}
19
     */
20 3
    public function __construct(ApiInterface $logger)
21
    {
22 3
        $this->logger = $logger;
23 3
    }
24
25
    /**
26
     * {@inheritDoc}
27
     */
28 1
    public function collect(Request $request, Response $response, \Exception $exception = null)
29
    {
30 1
        $this->data['calls'] = $this->logger->getCalls();
31 1
        $this->data['calls_count'] = $this->logger->getCallsCount();
32 1
    }
33
34
    /**
35
     * {@inheritDoc}
36
     */
37 1
    public function getName()
38
    {
39 1
        return 'api';
40
    }
41
42
    /**
43
     * {@inheritDoc}
44
     */
45 1
    public function getCalls()
46
    {
47 1
        return $this->data['calls'];
48
    }
49
50
    /**
51
     * {@inheritDoc}
52
     */
53 1
    public function getCallsCount()
54
    {
55 1
        return $this->data['calls_count'];
56
    }
57
58 1
    public function getTime()
59
    {
60 1
        $total = 0;
61 1
        foreach($this->data['calls'] as $call)
62 1
            $total += $call['time'];
63
64 1
        return $total;
65
    }
66
67 1
    public function reset()
68
    {
69 1
        $this->data = [];
70 1
    }
71
72
}