Completed
Push — master ( e22f7e...4537c6 )
by Evgenij
06:03
created

AbstractIo::getLastPhpErrorMessage()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2.0116

Importance

Changes 0
Metric Value
dl 0
loc 11
ccs 6
cts 7
cp 0.8571
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 7
nc 2
nop 0
crap 2.0116
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
     * Socket buffer size
21
     */
22
    const SOCKET_BUFFER_SIZE = 8192;
23
24
    /**
25
     * Amount of attempts to set data
26
     */
27
    const IO_ATTEMPTS = 10;
28
29
    /**
30
     * Socket
31
     *
32
     * @var SocketInterface
33
     */
34
    protected $socket;
35
36
    /**
37
     * AbstractIo constructor.
38
     *
39
     * @param SocketInterface $socket Socket object
40
     */
41 217
    public function __construct(SocketInterface $socket)
42
    {
43 217
        $this->socket = $socket;
44 217
    }
45
46
    /**
47
     * Return last php error message as string
48
     *
49
     * @return string
50
     */
51 4
    protected function getLastPhpErrorMessage()
52
    {
53 4
        $lastError = error_get_last();
54 4
        if (!empty($lastError)) {
55 4
            $phpMessage = explode(':', $lastError['message'], 2);
56 4
            $phpMessage = trim(trim(end($phpMessage)), '.') . '.';
57 4
            return $phpMessage;
58
        }
59
60
        return '';
61
    }
62
}
63