JsonRpc   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 32
Duplicated Lines 37.5 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 95.24%

Importance

Changes 0
Metric Value
dl 12
loc 32
ccs 20
cts 21
cp 0.9524
rs 10
c 0
b 0
f 0
wmc 6
lcom 0
cbo 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A encode() 0 16 2
A decode() 12 12 4

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Laravoole\WebsocketCodec;
4
5
class JsonRpc implements CodecInterface
6
{
7 4
    public static function encode($statusCode, $method, $content, $echo)
8
    {
9 4
        if($statusCode >= 400) {
10 4
            $error = $content;
11 4
            $content = null;
12 2
        } else {
13 4
            $error = null;
14
        }
15 4
        return json_encode([
16 4
            'status' => $statusCode,
17 4
            'method' => $method,
18 4
            'result' => $content,
19 4
            'error' => $error,
20 4
            'id' => $echo,
21 2
        ]);
22
    }
23
24 4 View Code Duplication
    public static function decode($data)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
25
    {
26 4
        $data = @json_decode($data);
27 4
        if(!isset($data->method) || !isset($data->params)) {
28
            return;
29
        }
30
        return [
31 4
            'method' => $data->method,
32 4
            'params' => $data->params,
33 4
            'echo' => isset($data->id) ? $data->id : null,
34 2
        ];
35
    }
36
}
37