BinnList::addVal()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 0
cts 0
cp 0
rs 10
cc 1
nc 1
nop 1
crap 2
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