Completed
Push — master ( 955d05...19c28e )
by David
03:37
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
namespace Http\Client\Common;
4
5
use Http\Client\HttpAsyncClient;
6
use Http\Client\HttpClient;
7
8
/**
9
 * A flexible http client, which implements both interface and will emulate
10
 * one contract, the other, or none at all depending on the injected client contract.
11
 *
12
 * @author Joel Wurtz <[email protected]>
13
 */
14
final class FlexibleHttpClient implements HttpClient, HttpAsyncClient
15
{
16
    use HttpClientDecorator;
17
    use HttpAsyncClientDecorator;
18
19
    /**
20
     * @param HttpClient|HttpAsyncClient $client
21
     */
22 34
    public function __construct($client)
23
    {
24 34
        if (!($client instanceof HttpClient) && !($client instanceof HttpAsyncClient)) {
25 1
            throw new \LogicException('Client must be an instance of Http\\Client\\HttpClient or Http\\Client\\HttpAsyncClient');
26
        }
27
28 33
        $this->httpClient = $client;
0 ignored issues
show
Documentation Bug introduced by
It seems like $client can also be of type object<Http\Client\HttpAsyncClient>. However, the property $httpClient is declared as type object<Http\Client\HttpClient>. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
29 33
        $this->httpAsyncClient = $client;
0 ignored issues
show
Documentation Bug introduced by
It seems like $client can also be of type object<Http\Client\HttpClient>. However, the property $httpAsyncClient is declared as type object<Http\Client\HttpAsyncClient>. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
30
31 33
        if (!($this->httpClient instanceof HttpClient)) {
32 11
            $this->httpClient = new EmulatedHttpClient($this->httpClient);
33
        }
34
35 33
        if (!($this->httpAsyncClient instanceof HttpAsyncClient)) {
36 21
            $this->httpAsyncClient = new EmulatedHttpAsyncClient($this->httpAsyncClient);
37
        }
38 33
    }
39
}
40