ApiDataCollector   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 8
eloc 13
dl 0
loc 60
c 0
b 0
f 0
ccs 20
cts 20
cp 1
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A collect() 0 4 1
A getCalls() 0 3 1
A getCallsCount() 0 3 1
A __construct() 0 3 1
A reset() 0 3 1
A getName() 0 3 1
A getTime() 0 7 2
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
}