Completed
Branch 0.4-dev (79cc15)
by Evgenij
03:32
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 198
    public function __construct(SocketInterface $socket)
42
    {
43 198
        $this->socket = $socket;
44 198
    }
45
46
    /**
47
     * Return last php error message as string
48
     *
49
     * @return string
50
     */
51 3
    protected function getLastPhpErrorMessage()
52
    {
53 3
        $lastError = error_get_last();
54 3
        if ($lastError) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $lastError of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
55 3
            $phpMessage = explode(':', $lastError['message'], 2);
56 3
            $phpMessage = trim(trim(end($phpMessage)), '.') . '.';
57 3
            return $phpMessage;
58
        }
59
60
        return '';
61
    }
62
}
63