1 | <?php |
||
20 | final class StreamConnection implements Connection |
||
21 | { |
||
22 | public const DEFAULT_URI = 'tcp://127.0.0.1:3301'; |
||
23 | |||
24 | private const DEFAULT_OPTIONS = [ |
||
25 | 'connect_timeout' => 5, |
||
26 | 'socket_timeout' => 5, |
||
27 | 'tcp_nodelay' => true, |
||
28 | 'persistent' => false, |
||
29 | ]; |
||
30 | |||
31 | /** @var resource|null */ |
||
32 | private $stream; |
||
33 | |||
34 | /** @var resource|null */ |
||
35 | private $streamContext; |
||
36 | |||
37 | /** @var string */ |
||
38 | private $uri; |
||
39 | |||
40 | /** @var non-empty-array<string, mixed> */ |
||
41 | private $options; |
||
42 | |||
43 | /** @var Greeting|null */ |
||
44 | private $greeting; |
||
45 | |||
46 | /** |
||
47 | * @param string $uri |
||
48 | * @param array<string, mixed> $options |
||
49 | */ |
||
50 | private function __construct($uri, $options) |
||
51 | { |
||
52 | $this->uri = $uri; |
||
53 | $this->options = $options + self::DEFAULT_OPTIONS; |
||
54 | } |
||
55 | |||
56 | public static function createTcp(string $uri = self::DEFAULT_URI, array $options = []) : self |
||
57 | { |
||
58 | $self = new self($uri, $options); |
||
59 | |||
60 | if ($self->options['tcp_nodelay'] ?? false) { |
||
61 | $self->streamContext = \stream_context_create(['socket' => ['tcp_nodelay' => true]]); |
||
62 | } |
||
63 | |||
64 | return $self; |
||
65 | } |
||
66 | |||
67 | public static function createUds(string $uri, array $options = []) : self |
||
71 | |||
72 | public static function create(string $uri, array $options = []) : self |
||
73 | { |
||
78 | |||
79 | /** |
||
80 | * @see https://github.com/vimeo/psalm/issues/3021 |
||
81 | * @psalm-suppress InvalidNullableReturnType |
||
82 | */ |
||
83 | public function open() : Greeting |
||
125 | |||
126 | public function close() : void |
||
136 | |||
137 | public function isClosed() : bool |
||
141 | |||
142 | public function send(string $data) : string |
||
154 | |||
155 | private function read(int $length, string $errorMessage) : string |
||
166 | } |
||
167 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..