TransportCollector   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 84
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 5
c 1
b 0
f 1
lcom 1
cbo 3
dl 0
loc 84
ccs 0
cts 31
cp 0
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A setCredentials() 0 6 1
A getCredentials() 0 4 1
A sendRequest() 0 17 1
A getRequests() 0 4 1
1
<?php
2
3
namespace Speicher210\FastbillBundle\DataCollector;
4
5
use Speicher210\Fastbill\Api\ApiCredentials;
6
use Speicher210\Fastbill\Api\Transport\TransportInterface;
7
use Symfony\Component\Stopwatch\Stopwatch;
8
9
/**
10
 * Transport data collector.
11
 */
12
class TransportCollector implements TransportInterface
13
{
14
    /**
15
     * The inner service.
16
     *
17
     * @var TransportInterface
18
     */
19
    protected $service;
20
21
    /**
22
     * The stopwatch.
23
     *
24
     * @var Stopwatch
25
     */
26
    protected $stopwatch;
27
28
    /**
29
     * The made requests.
30
     *
31
     * @var array
32
     */
33
    protected $requests = array();
34
35
    /**
36
     * Constructor.
37
     *
38
     * @param TransportInterface $service The inner transport.
39
     * @param Stopwatch $stopwatch The stopwatch.
40
     */
41
    public function __construct(TransportInterface $service, Stopwatch $stopwatch)
42
    {
43
        $this->service = $service;
44
        $this->stopwatch = $stopwatch;
45
    }
46
47
    /**
48
     * {@inheritdoc}
49
     */
50
    public function setCredentials(ApiCredentials $credentials)
51
    {
52
        $this->service->setCredentials($credentials);
53
54
        return $this;
55
    }
56
57
    /**
58
     * {@inheritdoc}
59
     */
60
    public function getCredentials()
61
    {
62
        return $this->service->getCredentials();
63
    }
64
65
    /**
66
     * {@inheritdoc}
67
     */
68
    public function sendRequest($body)
69
    {
70
        $stopwatchId = uniqid('speicher210_fastbill.collector.transport.');
71
        $this->stopwatch->start($stopwatchId);
72
73
        $return = $this->service->sendRequest($body);
74
75
        $stop = $this->stopwatch->stop($stopwatchId);
76
77
        $this->requests[] = array(
78
            'time' => $stop->getDuration(),
79
            'request' => json_decode($body, true),
80
            'response' => json_decode($return, true),
81
        );
82
83
        return $return;
84
    }
85
86
    /**
87
     * Get the requests.
88
     *
89
     * @return array
90
     */
91
    public function getRequests()
92
    {
93
        return $this->requests;
94
    }
95
}
96