StopwatchHttpAdapter::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 2
crap 1
1
<?php
2
3
/*
4
 * This file is part of the Ivory Http Adapter package.
5
 *
6
 * (c) Eric GELOEN <[email protected]>
7
 *
8
 * For the full copyright and license information, please read the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Ivory\HttpAdapter;
13
14
use Ivory\HttpAdapter\Message\InternalRequestInterface;
15
use Symfony\Component\Stopwatch\Stopwatch;
16
17
/**
18
 * @author GeLo <[email protected]>
19
 */
20
class StopwatchHttpAdapter extends PsrHttpAdapterDecorator
21
{
22
    /**
23
     * @var Stopwatch\Stopwatch
24
     */
25
    private $stopwatch;
26
27
    /**
28
     * @param HttpAdapterInterface $httpAdapter
29
     * @param Stopwatch            $stopwatch
30
     */
31 45
    public function __construct(HttpAdapterInterface $httpAdapter, Stopwatch $stopwatch)
32
    {
33 45
        parent::__construct($httpAdapter);
34
35 45
        $this->stopwatch = $stopwatch;
0 ignored issues
show
Documentation Bug introduced by Eric GELOEN
It seems like $stopwatch of type object<Symfony\Component\Stopwatch\Stopwatch> is incompatible with the declared type object<Symfony\Component...ch\Stopwatch\Stopwatch> of property $stopwatch.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
36 45
    }
37
38
    /**
39
     * {@inheritdoc}
40
     */
41 18 View Code Duplication
    protected function doSendInternalRequest(InternalRequestInterface $internalRequest)
0 ignored issues
show
Duplication introduced by Eric GELOEN
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
42
    {
43 18
        $this->stopwatch->start($name = 'ivory.http_adapter');
44
45
        try {
46 18
            $result = parent::doSendInternalRequest($internalRequest);
47 16
        } catch (\Exception $e) {
48 9
            $this->stopwatch->stop($name);
49
50 9
            throw $e;
51
        }
52
53 9
        $this->stopwatch->stop($name);
54
55 9
        return $result;
56
    }
57
58
    /**
59
     * {@inheritdoc}
60
     */
61 18 View Code Duplication
    protected function doSendInternalRequests(array $internalRequests)
0 ignored issues
show
Duplication introduced by Eric GELOEN
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
62
    {
63 18
        $this->stopwatch->start($name = 'ivory.http_adapter');
64
65
        try {
66 18
            $result = parent::doSendInternalRequests($internalRequests);
67 16
        } catch (\Exception $e) {
68 9
            $this->stopwatch->stop($name);
69
70 9
            throw $e;
71
        }
72
73 9
        $this->stopwatch->stop($name);
74
75 9
        return $result;
76
    }
77
}
78