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

Connection::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 0
cts 7
cp 0
rs 9.6666
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 1
crap 2
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
15
use Nekland\Woketo\Core\AbstractConnection;
16
use React\Promise\PromiseInterface;
17
use React\Stream\Stream;
18
19
class Connection extends AbstractConnection
20
{
21
    /**
22
     * @var Stream
23
     */
24
    private $stream;
25
26
    public function __construct(PromiseInterface $clientPromise)
27
    {
28
        $clientPromise->then(function (Stream $stream) {
29
            $this->stream = $stream;
30
            $this->onConnection($stream);
31
        }, function (\Exception $error){
32
            $this->onError($error);
0 ignored issues
show
Unused Code introduced by
The call to the method Nekland\Woketo\Client\Connection::onError() seems un-needed as the method has no side-effects.

PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.

Let’s take a look at an example:

class User
{
    private $email;

    public function getEmail()
    {
        return $this->email;
    }

    public function setEmail($email)
    {
        $this->email = $email;
    }
}

If we look at the getEmail() method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:

$user = new User();
$user->getEmail(); // This line could safely be removed as it has no effect.

On the hand, if we look at the setEmail(), this method _has_ side-effects. In the following case, we could not remove the method call:

$user = new User();
$user->setEmail('email@domain'); // This line has a side-effect (it changes an
                                 // instance variable).
Loading history...
33
        });
34
    }
35
36
    private function onConnection(Stream $stream)
37
    {
38
        $stream->on('message', function (string $data) {
39
            $this->onMessage($data);
40
        });
41
    }
42
43
    protected function processHandshake(string $data)
44
    {
45
        // TODO: Implement processHandshake() method.
46
    }
47
48
    protected function processMessage(string $data)
49
    {
50
        // TODO: Implement processMessage() method.
51
    }
52
53
    /**
54
     * @param \Exception|string $error
55
     */
56
    private function onError($error)
0 ignored issues
show
Unused Code introduced by
The parameter $error 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...
57
    {
58
59
    }
60
}