Passed
Push — master ( c493bc...401b4d )
by Nikita
03:14 queued 11s
created

BinnList::_binnLoad()   C

Complexity

Conditions 16
Paths 44

Size

Total Lines 90
Code Lines 60

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 41
CRAP Score 21.6619

Importance

Changes 0
Metric Value
cc 16
eloc 60
nc 44
nop 1
dl 0
loc 90
ccs 41
cts 57
cp 0.7193
crap 21.6619
rs 5.5666
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace Knik\Binn;
4
5
use Knik\Binn\Contracts\Container;
6
7
/**
8
 * @method BinnList addBool(boolean $value)
9
 * @method BinnList addUint8(integer $value)
10
 * @method BinnList addUint16(integer $value)
11
 * @method BinnList addUint32(integer $value)
12
 * @method BinnList addUint64(integer $value)
13
 * @method BinnList addInt8(integer $value)
14
 * @method BinnList addInt16(integer $value)
15
 * @method BinnList addInt32(integer $value)
16
 * @method BinnList addInt64(integer $value)
17
 * @method BinnList addFloat(string $value)
18
 * @method BinnList addDouble(string $value)
19
 * @method BinnList addStr(string $value)
20
 * @method BinnList addMap(Binn $value)
21
 * @method BinnList addObject(Binn $value)
22
 *
23
 */
24
class BinnList extends Binn implements Container
25
{
26
    protected $binnType = self::BINN_LIST;
27
28
    private $methodsAssignments = [
29
        'addBool'      => self::BINN_BOOL,
30
        'addUint8'     => self::BINN_UINT8,
31
        'addUint16'    => self::BINN_UINT16,
32
        'addUint32'    => self::BINN_UINT32,
33
        'addUint64'    => self::BINN_UINT64,
34
        'addInt8'      => self::BINN_INT8,
35
        'addInt16'     => self::BINN_INT16,
36
        'addInt32'     => self::BINN_INT32,
37
        'addInt64'     => self::BINN_INT64,
38
        'addFloat'     => self::BINN_FLOAT32,
39
        'addDouble'    => self::BINN_FLOAT64,
40
        'addStr'       => self::BINN_STRING,
41
        'addList'      => self::BINN_LIST,
42
        'addMap'       => self::BINN_MAP,
43
        'addObject'    => self::BINN_OBJECT,
44
    ];
45
46
    public function __call($name, $arguments)
47
    {
48
        if (array_key_exists($name, $this->methodsAssignments)) {
49
            $this->addVal($arguments[0]);
50 42
            return $this;
51
        }
52 42
53
        throw new \Exception("Call to undefined method {$name}");
54 42
    }
55 6
56
    public function addList(BinnList $list): void
57
    {
58 42
        $this->addVal($list->toArray());
59
    }
60
61
    private function addVal($value): void
62
    {
63
        $this->items[] = $value;
64
    }
65
}
66