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

AbstractIo   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 90%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 0
dl 0
loc 46
ccs 9
cts 10
cp 0.9
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getLastPhpErrorMessage() 0 11 2
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