Completed
Branch 0.4-dev (d27253)
by Evgenij
03:26
created

AbstractIo::throwNetworkSocketExceptionIf()   A

Complexity

Conditions 4
Paths 5

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 5.024

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 12
ccs 6
cts 10
cp 0.6
rs 9.2
cc 4
eloc 8
nc 5
nop 3
crap 5.024
1
<?php
2
/**
3
 * Async sockets
4
 *
5
 * @copyright Copyright (c) 2015-2017, 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\Socket\SocketInterface;
13
14
/**
15
 * Class AbstractIo
16
 */
17
abstract class AbstractIo implements IoInterface
18
{
19
    /**
20
     * Amount of attempts to set data
21
     */
22
    const IO_ATTEMPTS = 10;
23
24
    /**
25
     * Socket
26
     *
27
     * @var SocketInterface
28
     */
29
    protected $socket;
30
31
    /**
32
     * AbstractIo constructor.
33
     *
34
     * @param SocketInterface $socket Socket object
35
     */
36 217
    public function __construct(SocketInterface $socket)
37
    {
38 217
        $this->socket = $socket;
39 217
    }
40
41
    /**
42
     * Return last php error message as string
43
     *
44
     * @return string
45
     */
46 4
    protected function getLastPhpErrorMessage()
47
    {
48 4
        $lastError = error_get_last();
49 4
        if (!empty($lastError)) {
50 4
            $phpMessage = explode(':', $lastError['message'], 2);
51 4
            $phpMessage = trim(trim(end($phpMessage)), '.') . '.';
52 4
            return $phpMessage;
53
        }
54
55
        return '';
56
    }
57
}
58