Passed
Pull Request — master (#2)
by thomas
01:55
created

ValidatorFactory::versionResponse()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 0
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace BitWasp\Trezor\Bridge\Schema;
6
7
class ValidatorFactory
8
{
9
    const VERSION_RESPONSE_VALIDATOR = <<<JSON
10
{
11
    "title": "VersionResponse",
12
    "type": "object",
13
    "properties": {
14
        "version": {
15
            "type": "string"
16
        }
17
    },
18
    "required": ["version"]
19
}
20
JSON;
21
22
    const LIST_DEVICES_RESPONSE_VALIDATOR = <<<JSON
23
{
24
  "title": "ListDevicesResponse",
25
  "type": "array",
26
  "items": {
27
    "type": "object",
28
    "properties": {
29
      "path": {
30
        "type": "string"
31
      },
32
      "vendor": {
33
        "type": "number"
34
      },
35
      "product": {
36
        "type": "number"
37
      },
38
      "session": {
39
        "type": ["string", "null"]
40
      }
41
    },
42
    "required": [
43
      "path", "session"
44
    ]
45
  }
46
}
47
JSON;
48
49
    const ACQUIRE_RESPONSE_VALIDATOR = <<<JSON
50
{
51
  "title": "AcquireResponse",
52
  "type": "object",  
53
  "properties": {
54
    "session": {
55
      "type": "string"
56
    }
57
  },
58
  "required": [
59
    "session"
60
  ]
61
}
62
JSON;
63
64
    const RELEASE_RESPONSE_VALIDATOR = <<<JSON
65
{
66
  "title": "ReleaseResponse",
67
  "type": "object",  
68
  "properties": {},
69
  "required": []
70
}
71
JSON;
72
73
    const CALL_RESPONSE_VALIDATOR = <<<JSON
74
{
75
  "title": "CallResponse",
76
  "type": "object",  
77
  "properties": {
78
    "type": {
79
      "type": "string"
80
    },
81
    "body": {
82
      "type": "string"
83
    }
84
  },
85
  "required": [
86
    "type", "body"
87
  ]
88
}
89
JSON;
90
91 5
    public function versionResponse(): \stdClass
92
    {
93 5
        return json_decode(self::VERSION_RESPONSE_VALIDATOR);
94
    }
95
96 3
    public function listDevicesResponse(): \stdClass
97
    {
98 3
        return json_decode(self::LIST_DEVICES_RESPONSE_VALIDATOR);
99
    }
100
101 3
    public function acquireResponse(): \stdClass
102
    {
103 3
        return json_decode(self::ACQUIRE_RESPONSE_VALIDATOR);
104
    }
105
106 1
    public function releaseResponse(): \stdClass
107
    {
108 1
        return json_decode(self::RELEASE_RESPONSE_VALIDATOR);
109
    }
110
111
    public function callResponse(): \stdClass
112
    {
113
        return json_decode(self::CALL_RESPONSE_VALIDATOR);
114
    }
115
}
116