Completed
Pull Request — master (#128)
by Fabien
09:15
created

StackPlugin::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 3
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 Psr\Http\Message\ResponseInterface;
9
10
/**
11
 * @author Fabien Bourigault <[email protected]>
12
 *
13
 * @internal
14
 */
15
class StackPlugin implements Plugin
16
{
17
    /**
18
     * @var Collector
19
     */
20
    private $collector;
21
22
    /**
23
     * @var string
24
     */
25
    private $client;
26
27
    /**
28
     * @var Formatter
29
     */
30
    private $formatter;
31
32
    /**
33
     * @param Collector $collector
34
     * @param Formatter $formatter
35
     * @param string    $client
36
     */
37
    public function __construct(Collector $collector, Formatter $formatter, $client)
38
    {
39
        $this->collector = $collector;
40
        $this->formatter = $formatter;
41
        $this->client = $client;
42
    }
43
44
    /**
45
     * {@inheritdoc}
46
     */
47 View Code Duplication
    public function handleRequest(RequestInterface $request, callable $next, callable $first)
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...
48
    {
49
        $stack = new Stack($this->client, $this->formatter->formatRequest($request));
50
51
        $this->collector->addStack($stack);
52
53
        return $next($request)->then(function (ResponseInterface $response) use ($stack) {
54
            $stack->setResponse($this->formatter->formatResponse($response));
55
56
            return $response;
57
        }, function (Exception $exception) use ($stack) {
58
            $stack->setResponse($this->formatter->formatException($exception));
59
            $stack->setFailed(true);
60
61
            throw $exception;
62
        });
63
    }
64
}
65