Completed
Pull Request — master (#70)
by Márk
03:26
created

PluginClient::configure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 2
Bugs 2 Features 1
Metric Value
c 2
b 2
f 1
dl 0
loc 9
ccs 6
cts 6
cp 1
rs 9.6666
cc 1
eloc 5
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Http\Client\Plugin;
4
5
use Http\Client\HttpAsyncClient;
6
use Http\Client\HttpClient;
7
use Http\Client\Plugin\Exception\LoopException;
8
use Psr\Http\Message\RequestInterface;
9
10
/**
11
 * The client managing plugins and providing a decorator around HTTP Clients.
12
 *
13
 * @author Joel Wurtz <[email protected]>
14
 *
15
 * @deprecated since since version 1.1, and will be removed in 2.0. Use {@link \Http\Client\Common\PluginClient} instead.
16
 */
17
final class PluginClient implements HttpClient, HttpAsyncClient
18
{
19
    /**
20
     * @var \Http\Client\Common\PluginClient
21
     */
22
    private $pluginClient;
23
24
    /**
25
     * @param HttpClient|HttpAsyncClient $client
26
     * @param Plugin[]                   $plugins
27
     * @param array                      $options {
28
     *
29
     *     @var int $max_restarts
30
     * }
31
     *
32
     * @throws \RuntimeException if client is not an instance of HttpClient or HttpAsyncClient
33
     */
34 8
    public function __construct($client, array $plugins = [], array $options = [])
35
    {
36 8
        $this->pluginClient = new \Http\Client\Common\PluginClient($client, $plugins, $options);
37 8
    }
38
39
    /**
40
     * {@inheritdoc}
41
     */
42 4 View Code Duplication
    public function sendRequest(RequestInterface $request)
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...
43
    {
44
        try {
45 4
            return $this->pluginClient->sendRequest($request);
46 1
        } catch (\Http\Client\Common\Exception\LoopException $e) {
47 1
            throw new LoopException($e->getMessage(), $e->getRequest(), $e);
0 ignored issues
show
Deprecated Code introduced by
The class Http\Client\Plugin\Exception\LoopException has been deprecated with message: since since version 1.1, and will be removed in 2.0. Use {@link \Http\Client\Common\Exception\LoopException} instead.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
48
        }
49
    }
50
51
    /**
52
     * {@inheritdoc}
53
     */
54 2 View Code Duplication
    public function sendAsyncRequest(RequestInterface $request)
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...
55
    {
56
        try {
57 2
            return $this->pluginClient->sendAsyncRequest($request);
58
        } catch (\Http\Client\Common\Exception\LoopException $e) {
59
            throw new LoopException($e->getMessage(), $e->getRequest(), $e);
0 ignored issues
show
Deprecated Code introduced by
The class Http\Client\Plugin\Exception\LoopException has been deprecated with message: since since version 1.1, and will be removed in 2.0. Use {@link \Http\Client\Common\Exception\LoopException} instead.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
60
        }
61
    }
62
}
63