Completed
Branch master (1d1574)
by Evgenij
18:38
created

AbstractIo::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
/**
3
 * Async sockets
4
 *
5
 * @copyright Copyright (c) 2015-2016, Efimov Evgenij <[email protected]>
6
 *
7
 * This source file is subject to the MIT license that is bundled
8
 * with this source code in the file LICENSE.
9
 */
10
namespace AsyncSockets\Socket\Io;
11
12
use AsyncSockets\Exception\NetworkSocketException;
13
use AsyncSockets\Socket\SocketInterface;
14
15
/**
16
 * Class AbstractIo
17
 */
18
abstract class AbstractIo implements IoInterface
19
{
20
    /**
21
     * Socket buffer size
22
     */
23
    const SOCKET_BUFFER_SIZE = 8192;
24
25
    /**
26
     * Amount of attempts to set data
27
     */
28
    const IO_ATTEMPTS = 10;
29
30
    /**
31
     * Socket
32
     *
33
     * @var SocketInterface
34
     */
35
    protected $socket;
36
37
    /**
38
     * AbstractIo constructor.
39
     *
40
     * @param SocketInterface $socket Socket object
41
     */
42 159
    public function __construct(SocketInterface $socket)
43
    {
44 159
        $this->socket = $socket;
45 159
    }
46
47
    /**
48
     * Throw network operation exception
49
     *
50
     * @param bool   $condition Condition, which must evaluates to true for throwing exception
51
     * @param string $message Exception message
52
     *
53
     * @return void
54
     * @throws NetworkSocketException
55
     */
56 38
    protected function throwNetworkSocketExceptionIf($condition, $message)
57
    {
58 38
        if ($condition) {
59 10
            throw new NetworkSocketException($this->socket, $message);
60
        }
61 32
    }
62
}
63