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

PluginClient   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 46
Duplicated Lines 34.78 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 81.82%

Importance

Changes 11
Bugs 3 Features 1
Metric Value
wmc 5
c 11
b 3
f 1
lcom 1
cbo 2
dl 16
loc 46
ccs 9
cts 11
cp 0.8182
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A sendRequest() 8 8 2
A sendAsyncRequest() 8 8 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
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