StopwatchHttpAdapter   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 58
Duplicated Lines 55.17 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 32
loc 58
ccs 20
cts 20
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A doSendInternalRequest() 16 16 2
A doSendInternalRequests() 16 16 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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
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
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
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