SetBan::jsonSerialize()   A
last analyzed

Complexity

Conditions 4
Paths 1

Size

Total Lines 10
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 4

Importance

Changes 0
Metric Value
dl 0
loc 10
c 0
b 0
f 0
ccs 7
cts 7
cp 1
rs 9.2
cc 4
eloc 8
nc 1
nop 0
crap 4
1
<?php
2
3
namespace ZenCash\Rpc\Command\Network;
4
5
use ZenCash\Rpc\Command;
6
use ZenCash\Rpc\Command\Network\SetBan\Command as CommandEnum;
7
8
final class SetBan implements Command
9
{
10
    private const METHOD = 'setban';
11
    private $ip;
12
    private $command;
13
    private $banTime;
14
    private $absolute;
15
16
17 4
    public function __construct(string $ip, CommandEnum $command, ?int $banTime, ?bool $absolute)
18
    {
19 4
        $this->ip = $ip;
20 4
        $this->command = $command;
21 4
        $this->banTime = $banTime;
22 4
        $this->absolute = $absolute;
23 4
    }
24
25 4
    public function jsonSerialize(): object
26
    {
27
        return (object) [
28 4
            'jsonrpc' => Command::JSON_RPC_VERSION,
29
            'id'      => Command::ID,
30 4
            'method'  => self::METHOD,
31 4
            'params' => array_merge(
32 4
                [ $this->ip, (string) $this->command ],
33 4
                !is_null($this->banTime) ? [ $this->banTime ] : [ ],
34 4
                !is_null($this->absolute) && !is_null($this->banTime) ? [ $this->absolute ] : [ ]
35
            )
36
        ];
37
    }
38
}
39