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

ClientHandshake   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 62.5%

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 2
dl 0
loc 34
ccs 10
cts 16
cp 0.625
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A verify() 0 4 1
A createRequest() 0 4 1
A sign() 0 21 4
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\Rfc6455\Handshake;
13
14
use Nekland\Woketo\Exception\RuntimeException;
15
use Nekland\Woketo\Http\Request;
16
use Nekland\Woketo\Http\Response;
17
18
class ClientHandshake implements HandshakeInterface
19
{
20 2
    public function sign($request, Response $response = null)
21
    {
22 2
        if ($response !== null) {
23 1
            throw new RuntimeException('You cannot give a Response as the client should create the key.');
24
        }
25
26 1
        if (!$request instanceof Request) {
27
            throw new RuntimeException(sprintf('Expected request at first argument but got %s', gettype($request)));
28
        }
29
30 1
        $key = '';
31 1
        for ($i = 0; $i < 16; $i++) {
32 1
            $key .= chr(mt_rand(0,255));
33
        }
34
35 1
        $key = base64_encode($key);
36
37 1
        $request->setKey($key);
38
39 1
        return $key;
40
    }
41
42
    public function verify($request)
43
    {
44
        // TODO: Implement verify() method.
45
    }
46
47
    public function createRequest(string $uri)
0 ignored issues
show
Unused Code introduced by
The parameter $uri 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...
48
    {
49
        $request = Request::create('');
0 ignored issues
show
Unused Code introduced by
$request 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...
50
    }
51
}
52