Completed
Pull Request — master (#70)
by Márk
04:10
created

PluginClient::sendAsyncRequest()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 8
Ratio 100 %

Code Coverage

Tests 3
CRAP Score 2.2559

Importance

Changes 6
Bugs 1 Features 0
Metric Value
c 6
b 1
f 0
dl 8
loc 8
ccs 3
cts 5
cp 0.6
rs 9.4285
cc 2
eloc 5
nc 2
nop 1
crap 2.2559
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 19 and the first side effect is on line 5.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
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
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