Completed
Push — master ( bac1bc...5acb47 )
by Ivo
07:35
created

SoapDataCollector   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 47.5%

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 2
dl 0
loc 71
ccs 19
cts 40
cp 0.475
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A collect() 0 13 3
A reset() 0 8 1
A getName() 0 4 1
A getTotal() 0 4 1
A getTime() 0 4 1
A getRequests() 0 4 1
1
<?php
2
3
namespace Freshcells\SoapClientBundle\DataCollector;
4
5
use Symfony\Component\HttpFoundation\Request;
6
use Symfony\Component\HttpFoundation\Response;
7
use Symfony\Component\HttpKernel\DataCollector\DataCollector;
8
9
class SoapDataCollector extends DataCollector
10
{
11
    private $callRegistry;
12
13
    /**
14
     * SoapDataCollector constructor.
15
     * @param SoapCallRegistry $callRegistry
16
     */
17 4
    public function __construct(SoapCallRegistry $callRegistry)
18
    {
19 4
        $this->callRegistry = $callRegistry;
20 4
    }
21
22
    /**
23
     * {@inheritdoc}
24
     */
25 4
    public function collect(Request $request, Response $response, \Exception $exception = null)
26
    {
27 4
        $time = 0;
28 4
        foreach ($this->callRegistry->getCalls() as $call) {
29 4
            $time += (isset($call['duration']) ? $call['duration'] : 0);
30
        }
31
32 4
        $this->data = [
33 4
            'total'    => count($this->callRegistry->getCalls()),
34 4
            'time'     => $time,
35 4
            'requests' => $this->callRegistry->getCalls(),
36
        ];
37 4
    }
38
39 4
    public function reset()
40
    {
41 4
        $this->data = [
42
            'total'    => 0,
43
            'time'     => 0,
44
            'requests' => [],
45
        ];
46 4
    }
47
48
    /**
49
     * {@inheritdoc}
50
     */
51 4
    public function getName()
52
    {
53 4
        return 'freshcells_soap_client';
54
    }
55
56
    /**
57
     * @return int
58
     */
59 4
    public function getTotal()
60
    {
61 4
        return $this->data['total'];
62
    }
63
64
    /**
65
     * @return int Time in milliseconds.
66
     */
67
    public function getTime()
68
    {
69
        return $this->data['time'];
70
    }
71
72
    /**
73
     * @return array
74
     */
75
    public function getRequests()
76
    {
77
        return $this->data['requests'];
78
    }
79
}
80