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

Connection::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 0
cts 8
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 7
nc 1
nop 2
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 Nekland\Woketo\Rfc6455\MessageProcessor;
17
use React\Promise\PromiseInterface;
18
use React\Stream\Stream;
19
20
class Connection extends AbstractConnection
21
{
22
    /**
23
     * @var Stream
24
     */
25
    private $stream;
26
27
    public function __construct(PromiseInterface $clientPromise, MessageProcessor $messageProcessor)
28
    {
29
        parent::__construct($messageProcessor, new ClientHandshake());
30
        $clientPromise->then(function (Stream $stream) {
31
            $this->stream = $stream;
32
            $this->onConnection($stream);
33
        }, function (\Exception $error){
34
            $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...
35
        });
36
    }
37
38
    private function onConnection(Stream $stream)
39
    {
40
        $stream->on('message', function (string $data) {
41
            $this->onMessage($data);
42
        });
43
    }
44
45
    protected function processHandshake(string $data)
46
    {
47
        // TODO: Implement processHandshake() method.
48
    }
49
50
    protected function processMessage(string $data)
51
    {
52
        // TODO: Implement processMessage() method.
53
    }
54
55
    /**
56
     * @param \Exception|string $error
57
     */
58
    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...
59
    {
60
61
    }
62
}