Failed Conditions
Pull Request — master (#1)
by Yo
05:58 queued 03:23
created

JsonRpcRawRequest::addItem()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
cc 3
eloc 8
nc 2
nop 1
dl 0
loc 15
ccs 0
cts 13
cp 0
crap 12
rs 9.4285
c 0
b 0
f 0
1
<?php
2
namespace Yoanm\JsonRpcServer\Infra\RawObject;
3
4
use Yoanm\JsonRpcServer\Domain\Model\JsonRpcRequest;
5
use Yoanm\JsonRpcServer\Domain\Model\JsonRpcResponse;
6
7
/**
8
 * Class JsonRpcRawRequest
9
 */
10
class JsonRpcRawRequest
11
{
12
    /** @var bool */
13
    private $isBatch;
14
    /** @var mixed[] */
15
    private $itemList = [];
16
17
    /**
18
     * @param bool|false $isBatch
19
     */
20
    public function __construct(bool $isBatch = false)
21
    {
22
        $this->isBatch = $isBatch;
23
    }
24
25
    /**
26
     * @param JsonRpcRequest|\Exception $item
27
     *
28
     * @return JsonRpcRawRequest
29
     */
30
    public function addItem(object $item) : JsonRpcRawRequest
31
    {
32
        if (!$item instanceof JsonRpcResponse && !$item instanceof \Exception) {
33
            throw new \InvalidArgumentException(
34
                sprintf(
35
                    'item must be either an instance of %s or an instance of %s',
36
                    JsonRpcRequest::class,
37
                    \Exception::class
38
                )
39
            );
40
        }
41
42
        $this->itemList[] = $item;
43
44
        return $this;
45
    }
46
47
    /**
48
     * @return boolean
49
     */
50
    public function isBatch() : bool
51
    {
52
        return $this->isBatch;
53
    }
54
55
    /**
56
     * @return (JsonRpcRequest|\Exception)[]
57
     */
58
    public function getItemtList() : array
59
    {
60
        return $this->itemList;
61
    }
62
}
63