SetBan   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
dl 0
loc 27
c 0
b 0
f 0
ccs 13
cts 13
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A jsonSerialize() 0 10 4
A __construct() 0 6 1
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