Completed
Push — master ( 4bee86...913926 )
by Denis
04:17
created

RequestBuilder::build()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 21
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 21
rs 9.3142
c 0
b 0
f 0
cc 3
eloc 12
nc 4
nop 1
1
<?php
2
3
namespace PhpJsonRpc\Client;
4
5
use PhpJsonRpc\Core\Call\CallUnit;
6
use PhpJsonRpc\Core\CallSpecifier;
7
8
class RequestBuilder
9
{
10
    /**
11
     * @param CallSpecifier $call
12
     *
13
     * @return string
14
     */
15
    public function build(CallSpecifier $call): string
16
    {
17
        $response = [];
18
        $units    = $call->getUnits();
19
20
        foreach ($units as $unit) {
21
            /** @var CallUnit $unit */
22
            $response[] = [
23
                'jsonrpc' => '2.0',
24
                'method'  => $unit->getRawMethod(),
25
                'params'  => $unit->getRawParams(),
26
                'id'      => $unit->getRawId()
27
            ];
28
        }
29
30
        if ($call->isSingleCall()) {
31
            return json_encode($response[0]);
32
        }
33
34
        return json_encode($response);
35
    }
36
}
37