Completed
Pull Request — master (#100)
by Maxime
02:48
created

WebSocketClient::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 0
cts 7
cp 0
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 4
crap 6
1
<?php
2
3
/**
4
 * This file is a part of Woketo package.
5
 *
6
 * (c) Nekland <[email protected]>
7
 *
8
 * For the full license, take a look to the LICENSE file
9
 * on the root directory of this project
10
 */
11
12
namespace Nekland\Woketo\Client;
13
14
use Nekland\Woketo\Message\MessageHandlerInterface;
15
16
class WebSocketClient
17
{
18
    /**
19
     * @var int
20
     */
21
    private $port;
22
23
    /**
24
     * @var string
25
     */
26
    private $host;
27
28
    /**
29
     * @var array
30
     */
31
    private $config;
32
33
    public function __construct(int $port, string $host, array $config = [], $connectorFactory = null)
34
    {
35
        $this->port = $port;
36
        $this->host = $host;
37
        $this->connectorFactory = $connectorFactory ?: new ConnectorFactory();
0 ignored issues
show
Bug introduced by
The property connectorFactory does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
38
        $this->setConfig($config);
39
    }
40
41
    public function start(MessageHandlerInterface $handler)
0 ignored issues
show
Unused Code introduced by
The parameter $handler is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
42
    {
43
        if ($this->config['prod'] && \extension_loaded('xdebug')) {
44
            throw new \Exception('xdebug is enabled, it\'s a performance issue. Disable that extension or specify "prod" option to false.');
45
        }
46
47
        $connection = new Connection($this->connectorFactory->createConnector());
0 ignored issues
show
Unused Code introduced by
$connection is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
48
    }
49
50
    /**
51
     * @param array $config
52
     * @return self
53
     */
54
    public function setConfig(array $config = [])
55
    {
56
        $this->config = array_merge([
57
            'prod' => true
58
        ], $config);
59
60
        return $this;
61
    }
62
}