JsonRpcSchema   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Test Coverage

Coverage 97.56%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 34
c 2
b 0
f 0
dl 0
loc 54
ccs 40
cts 41
cp 0.9756
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A get() 0 45 2
1
<?php
2
3
/**
4
 * Created by PhpStorm.
5
 * Project: json_rpc_server
6
 * User: sv
7
 * Date: 23.03.2020
8
 * Time: 12:53
9
 */
10
11
declare(strict_types=1);
12
13
namespace Onnov\JsonRpcServer\Validator;
14
15
use Onnov\JsonRpcServer\Traits\JsonHelperTrait;
16
use stdClass;
17
18
/**
19
 * Class JsonRpcSchema
20
 *
21
 * @package App\Validator\Schema
22
 */
23
class JsonRpcSchema
24
{
25
    use JsonHelperTrait;
26
27
    /**
28
     * @param stdClass|null $paramsSchema
29
     *
30
     * @return stdClass
31
     */
32 8
    public function get(stdClass $paramsSchema = null): stdClass
33
    {
34 8
        $params = [
35 8
            'type' => [
36 8
                'object',
37 8
                'array',
38 8
                'string',
39 8
                'number',
40 8
                'boolean',
41 8
                'null',
42 8
            ],
43 8
        ];
44
45 8
        if ($paramsSchema !== null) {
46
            $params = $paramsSchema;
47
        }
48
49 8
        return $this->assocArrToObject(
50 8
            [
51 8
            'type'                 => 'object',
52 8
            'description'          => 'json rpc 2.0 request schema',
53 8
            'additionalProperties' => false,
54 8
            'required'             => [
55 8
                'jsonrpc',
56 8
                'method',
57 8
            ],
58 8
            'properties'           => [
59 8
                'jsonrpc' => [
60 8
                    'type' => 'string',
61 8
                    'enum' => [
62 8
                        '2.0',
63 8
                    ],
64 8
                ],
65 8
                'method'  => [
66 8
                    'type'     => 'string',
67 8
                    'examples' => [
68 8
                        'Foo.bar',
69 8
                    ],
70 8
                ],
71 8
                'params'  => $params,
72 8
                'id'      => [
73 8
                    'type' => [
74 8
                        'string',
75 8
                        'null',
76 8
                        'integer',
77 8
                    ],
78 8
                ],
79 8
            ],
80 8
            ]
81 8
        );
82
    }
83
}
84