Passed
Push — master ( 9e2fe0...082215 )
by Sam
03:30
created

src/Socket/StreamSocket.php (1 issue)

1
<?php
2
3
4
namespace Pheanstalk\Socket;
5
6
use Pheanstalk\Contract\SocketInterface;
7
use Pheanstalk\Exception\SocketException;
8
9
/**
10
 * A Socket implementation using the Streams extension
11
 */
12
class StreamSocket extends FileSocket
13
{
14 1
    public function __construct(
15
        string $host,
16
        int $port,
17
        int $connectTimeout
18
    ) {
19
20 1
        if (!function_exists('stream_socket_client')) {
21
            throw new \Exception('Streams extension not found');
22
        }
23
24 1
        $target = "tcp://$host:$port";
25 1
        $context = stream_context_create();
26 1
        $this->socket = stream_socket_client($target, $error, $errorMessage, $connectTimeout, null, $context);
0 ignored issues
show
Documentation Bug introduced by
It seems like stream_socket_client($ta...imeout, null, $context) can also be of type false. However, the property $socket is declared as type resource|null. 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...
27 1
        if ($this->socket === false) {
28
            throw new SocketException($errorMessage, $error);
29
        }
30
    }
31
}
32