Completed
Push — master ( 13f804...2fe2df )
by Nathan
03:52 queued 01:49
created

GetBlockTemplate   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
dl 0
loc 26
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 2
A jsonSerialize() 0 11 2
1
<?php
2
3
namespace ZenCash\Rpc\Command\Mining;
4
5
use ZenCash\Rpc\Command;
6
use ZenCash\Rpc\Validation\Exception\JsonFormatException;
7
use ZenCash\Rpc\Validation\Mining\GetBlockTemplateValidator;
8
9
final class GetBlockTemplate implements Command
10
{
11
    private const METHOD = 'getblocktemplate';
12
    private $json;
13
14
    /** @throws JsonFormatException */
15
    public function __construct(?string $json)
16
    {
17
        if (!is_null($json)) {
18
            GetBlockTemplateValidator::validate($json);
19
        }
20
21
        $this->json = $json;
22
    }
23
24
    public function jsonSerialize(): object
25
    {
26
        return (object) array_merge([
27
            'jsonrpc' => Command::JSON_RPC_VERSION,
28
            'id'      => Command::ID,
29
            'method'  => self::METHOD
30
        ], !is_null($this->json) ? [
31
            'params' => [
32
                $this->json
33
            ]
34
        ] : []);
35
    }
36
}
37