ClientSocket   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 2
dl 0
loc 21
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A createSocketResource() 0 17 3
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
11
namespace AsyncSockets\Socket;
12
13
use AsyncSockets\Exception\ConnectionException;
14
15
/**
16
 * Class ClientSocket
17
 */
18
class ClientSocket extends AbstractClientSocket
19
{
20
    /** {@inheritdoc} */
21 15
    protected function createSocketResource($address, $context)
22
    {
23 15
        $resource = stream_socket_client(
24 15
            $address,
25 15
            $errno,
26 15
            $errstr,
27 15
            null,
28 15
            STREAM_CLIENT_CONNECT | STREAM_CLIENT_ASYNC_CONNECT,
29
            $context
30 15
        );
31
32 15
        if ($errno || $resource === false) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $errno of type integer|null is loosely compared to true; this is ambiguous if the integer can be zero. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For integer values, zero is a special case, in particular the following results might be unexpected:

0   == false // true
0   == null  // true
123 == false // false
123 == null  // false

// It is often better to use strict comparison
0 === false // false
0 === null  // false
Loading history...
33 2
            throw new ConnectionException($this, $errstr, $errno);
34
        }
35
36 13
        return $resource;
37
    }
38
}
39