PluginClient::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 3
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Http\Client\Plugin;
4
5 1
@trigger_error('The '.__NAMESPACE__.'\PluginClient class is deprecated since version 1.1 and will be removed in 2.0. Use Http\Client\Common\PluginClient instead.', E_USER_DEPRECATED);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
6
7
use Http\Client\HttpAsyncClient;
8
use Http\Client\HttpClient;
9
use Http\Client\Plugin\Exception\LoopException;
10
use Psr\Http\Message\RequestInterface;
11
12
/**
13
 * The client managing plugins and providing a decorator around HTTP Clients.
14
 *
15
 * @author Joel Wurtz <[email protected]>
16
 *
17
 * @deprecated since since version 1.1, and will be removed in 2.0. Use {@link \Http\Client\Common\PluginClient} instead.
18
 */
19
final class PluginClient implements HttpClient, HttpAsyncClient
20
{
21
    /**
22
     * @var \Http\Client\Common\PluginClient
23
     */
24
    private $pluginClient;
25
26
    /**
27
     * @param HttpClient|HttpAsyncClient $client
28
     * @param Plugin[]                   $plugins
29
     * @param array                      $options {
30
     *
31
     *     @var int $max_restarts Number of times plugins may initiate a restart of the plugin chain. Defaults to 10.
32
     * }
33
     *
34
     * @throws \RuntimeException if client is not an instance of HttpClient or HttpAsyncClient
35
     */
36 8
    public function __construct($client, array $plugins = [], array $options = [])
37
    {
38 8
        $this->pluginClient = new \Http\Client\Common\PluginClient($client, $plugins, $options);
39 8
    }
40
41
    /**
42
     * {@inheritdoc}
43
     */
44 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...
45
    {
46
        try {
47 4
            return $this->pluginClient->sendRequest($request);
48 1
        } catch (\Http\Client\Common\Exception\LoopException $e) {
49 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...
50
        }
51
    }
52
53
    /**
54
     * {@inheritdoc}
55
     */
56 1 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...
57 1
    {
58
        try {
59 1
            return $this->pluginClient->sendAsyncRequest($request);
60
        } catch (\Http\Client\Common\Exception\LoopException $e) {
61
            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...
62
        }
63
    }
64
}
65