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

Connection::processHandshake()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

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