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

Connection::onError()   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\Exception\WebsocketException;
16
use React\Promise\PromiseInterface;
17
use React\Stream\Stream;
18
19
class Connection
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);
0 ignored issues
show
Bug introduced by
The method onMessage() does not seem to exist on object<Nekland\Woketo\Client\Connection>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
40
        });
41
    }
42
43
44
    private function processHandshake()
0 ignored issues
show
Unused Code introduced by
This method is not used, and could be removed.
Loading history...
45
    {
46
47
    }
48
49
    /**
50
     * @param \Exception|string $error
51
     */
52
    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...
53
    {
54
55
    }
56
}