Json   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 25
Duplicated Lines 48 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 12
loc 25
ccs 0
cts 15
cp 0
rs 10
c 0
b 0
f 0
wmc 5
lcom 0
cbo 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A encode() 0 9 1
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 Json implements CodecInterface
6
{
7
    public static function encode($statusCode, $method, $content, $echo)
8
    {
9
        return json_encode([
10
            's' => $statusCode,
11
            'm' => $method,
12
            'p' => $content,
13
            'e' => $echo,
14
        ]);
15
    }
16
17 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...
18
    {
19
        $data = @json_decode($data);
20
        if(!isset($data->m) || !isset($data->p)) {
21
            return;
22
        }
23
        return [
24
            'method' => $data->m,
25
            'params' => $data->p,
26
            'echo' => isset($data->e) ? $data->e : null,
27
        ];
28
    }
29
}
30