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

sineflow / clamav / 22576550024

02 Mar 2026 12:43PM UTC coverage: 94.215% (+18.1%) from 76.106%
22576550024

Pull #14

github

pmishev
Code review fixes
Pull Request #14: 2.0.0

41 of 42 new or added lines in 8 files covered. (97.62%)

1 existing line in 1 file now uncovered.

114 of 121 relevant lines covered (94.21%)

78.93 hits per line

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

74.07
/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)
230✔
21
    {
22
        $this->socketType = $socketType;
230✔
23
        $this->connectionArguments = $connectionArguments;
230✔
24
    }
25

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

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

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

48
        return $dataOut;
160✔
49
    }
50

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

62
            $hasError = @ socket_connect($this->socket, ...$this->connectionArguments);
160✔
63
            if ($hasError === false) {
160✔
64
                throw new SocketException('Connecting to socket failed', socket_last_error());
×
65
            }
66
        }
67
    }
68
}
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