• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

sineflow / clamav / 22552497760

01 Mar 2026 08:57PM UTC coverage: 94.643% (+18.5%) from 76.106%
22552497760

Pull #14

github

pmishev
Added unit tests
Pull Request #14: 2.0.0

45 of 48 new or added lines in 10 files covered. (93.75%)

3 existing lines in 1 file now uncovered.

106 of 112 relevant lines covered (94.64%)

67.95 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

76.0
/src/Socket/Socket.php
1
<?php
2

3
namespace Sineflow\ClamAV\Socket;
4

5
use Sineflow\ClamAV\Exception\SocketException;
6

7
class Socket
8
{
9
    const UNIX = \AF_UNIX;
10
    const NETWORK = \AF_INET;
11

12
    const MAX_READ_BYTES = 8192;
13

14
    private int $socketType;
15

16
    private array $connectionArguments;
17

18
    private ?\Socket $socket = null;
19

20
    public function __construct(int $socketType, array $connectionArguments)
210✔
21
    {
22
        $this->socketType = $socketType;
210✔
23
        $this->connectionArguments = $connectionArguments;
210✔
24
    }
25

26
    public function sendCommand(string $dataIn, int $flagsSend = 0, int $flagsReceive = MSG_WAITALL): string
140✔
27
    {
28
        $this->connect();
140✔
29

30
        if (false === socket_send($this->socket, $dataIn, strlen($dataIn), $flagsSend)) {
140✔
UNCOV
31
            throw new SocketException('Writing to socket failed', socket_last_error($this->socket));
×
32
        }
33
        $dataOut = '';
140✔
34

35
        do {
36
            $bytes = socket_recv($this->socket, $chunk, self::MAX_READ_BYTES, $flagsReceive);
140✔
37
            if (false === $bytes) {
140✔
UNCOV
38
                $socketError = socket_last_error($this->socket);
×
UNCOV
39
                socket_close($this->socket);
×
NEW
40
                throw new SocketException('Reading from socket failed', $socketError);
×
41
            }
42
            $dataOut .= $chunk;
140✔
43
        } while ($bytes);
140✔
44
        socket_close($this->socket);
140✔
45

46
        return $dataOut;
140✔
47
    }
48

49
    /**
50
     * @throws SocketException
51
     */
52
    private function connect(): void
140✔
53
    {
54
        if (!($this->socket instanceof \Socket)) {
140✔
55
            $this->socket = @ socket_create($this->socketType, SOCK_STREAM, 0);
140✔
56
            if ($this->socket === false) {
140✔
NEW
57
                throw new SocketException('Creating socket failed', socket_last_error());
×
58
            }
59

60
            $hasError = @ socket_connect($this->socket, ...$this->connectionArguments);
140✔
61
            if ($hasError === false) {
140✔
NEW
62
                throw new SocketException('Connecting to socket failed', socket_last_error());
×
63
            }
64
        }
65
    }
66
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc