Completed
Push — master ( e37e46...c75450 )
by David
01:07
created

src/FlexibleHttpClient.php (2 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
declare(strict_types=1);
4
5
namespace Http\Client\Common;
6
7
use Http\Client\HttpAsyncClient;
8
use Http\Client\HttpClient;
9
use Psr\Http\Client\ClientInterface;
10
11
/**
12
 * A flexible http client, which implements both interface and will emulate
13
 * one contract, the other, or none at all depending on the injected client contract.
14
 *
15
 * @author Joel Wurtz <[email protected]>
16
 */
17
final class FlexibleHttpClient implements HttpClient, HttpAsyncClient
18
{
19
    use HttpClientDecorator;
20
    use HttpAsyncClientDecorator;
21
22
    /**
23
     * @param ClientInterface|HttpAsyncClient $client
24
     */
25 34
    public function __construct($client)
26
    {
27 34 View Code Duplication
        if (!$client instanceof ClientInterface && !$client instanceof HttpAsyncClient) {
0 ignored issues
show
This code seems to be duplicated across 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...
28 1
            throw new \TypeError(
29 1
                sprintf('%s::__construct(): Argument #1 ($client) must be of type %s|%s, %s given', self::class, ClientInterface::class, HttpAsyncClient::class, get_debug_type($client))
0 ignored issues
show
The call to TypeError::__construct() has too many arguments starting with sprintf('%s::__construct...et_debug_type($client)).

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
30
            );
31
        }
32
33 33
        $this->httpClient = $client instanceof ClientInterface ? $client : new EmulatedHttpClient($client);
34 33
        $this->httpAsyncClient = $client instanceof HttpAsyncClient ? $client : new EmulatedHttpAsyncClient($client);
35 33
    }
36
}
37