Completed
Pull Request — master (#128)
by Fabien
07:21 queued 05:28
created

Collector::getProfile()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 0
cts 8
cp 0
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 2
crap 6
1
<?php
2
3
namespace Http\HttplugBundle\Collector;
4
5
use Exception;
6
use Http\Client\Common\Plugin;
7
use Psr\Http\Message\RequestInterface;
8
use Symfony\Component\HttpFoundation\Request;
9
use Symfony\Component\HttpFoundation\Response;
10
use Symfony\Component\HttpKernel\DataCollector\DataCollector;
11
12
class Collector extends DataCollector
13
{
14
    /**
15
     * @var Profile[]
16
     */
17
    private $profiles;
18
19
    public function __construct()
20
    {
21
        $this->profiles = [];
22
    }
23
24
    /**
25
     * {@inheritdoc}
26
     */
27
    public function collect(Request $request, Response $response, Exception $exception = null)
28
    {
29
        // We do not need to collect any data from the Symfony Request and Response
30
    }
31
32
    /**
33
     * {@inheritdoc}
34
     */
35
    public function getName()
36
    {
37
        return 'httplug';
38
    }
39
40
    /**
41
     * @param Plugin           $plugin
42
     * @param RequestInterface $request
43
     *
44
     * @return Profile
45
     */
46
    public function getProfile(Plugin $plugin, RequestInterface $request)
47
    {
48
        $key = spl_object_hash($plugin).'-'.spl_object_hash($request);
49
50
        if (!isset($this->profiles[$key])) {
51
            $this->profiles[$key] = new Profile($plugin, $request);
52
        }
53
54
        return $this->profiles[$key];
55
    }
56
}
57