Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
n/a
0 / 0
n/a
0 / 0
CRAP
n/a
0 / 0
1<?php
2
3declare(strict_types=1);
4
5namespace AqwSocketClient\Interfaces;
6
7use RuntimeException;
8
9/**
10 * Abstraction over a raw TCP socket connection.
11 * Implement this interface to provide a testable/mockable socket.
12 */
13interface SocketInterface
14{
15    /**
16     * Creates the underlying socket resource.
17     *
18     * @throws RuntimeException on failure
19     */
20    public function create(): void;
21
22    /**
23     * Connects to the given host and port.
24     *
25     * @throws RuntimeException on failure
26     */
27    public function connect(string $hostname, int $port): void;
28
29    /**
30     * Closes the socket.
31     */
32    public function close(): void;
33
34    /**
35     * Reads exactly $length bytes from the socket.
36     *
37     * @throws RuntimeException on failure
38     * @return array{bytes: int, chunk: string}
39     */
40    public function read(int $length): array;
41
42    /**
43     * Sends $data over the socket.
44     *
45     * @throws RuntimeException on failure
46     * @return int bytes actually sent
47     */
48    public function send(string $data): int;
49}