TableValue   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 33.33 %

Coupling/Cohesion

Components 0
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
c 0
b 0
f 0
lcom 0
cbo 5
dl 12
loc 36
ccs 14
cts 14
cp 1
rs 10

2 Methods

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

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 ButterAMQP\Value;
4
5
use ButterAMQP\Buffer;
6
7
class TableValue extends AbstractValue
8
{
9
    /**
10
     * @param array $value
11
     *
12
     * @return string
13
     */
14 21
    public static function encode($value)
15
    {
16 21
        $data = '';
17
18 21
        foreach ($value as $key => $element) {
19 21
            $data .= ShortStringValue::encode($key).TypifiedValue::encode($element);
20 21
        }
21
22 21
        return LongValue::encode(strlen($data)).$data;
23
    }
24
25
    /**
26
     * @param Buffer $data
27
     *
28
     * @return array
29
     */
30 21 View Code Duplication
    public static function decode(Buffer $data)
31
    {
32 21
        $length = LongValue::decode($data);
33 21
        $buffer = new Buffer($data->read($length));
34 21
        $elements = [];
35
36 21
        while (!$buffer->eof()) {
37 21
            $elements[ShortStringValue::decode($buffer)] = TypifiedValue::decode($buffer);
38 21
        }
39
40 21
        return $elements;
41
    }
42
}
43