Total Complexity | 8 |
Total Lines | 80 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
7 | abstract Class Builder |
||
8 | { |
||
9 | /** |
||
10 | * The API resource |
||
11 | * |
||
12 | * @var \tbclla\Revolut\Interfaces\Buildable |
||
13 | */ |
||
14 | protected $resource; |
||
15 | |||
16 | /** |
||
17 | * The unique ID of the request |
||
18 | * |
||
19 | * @var string |
||
20 | */ |
||
21 | public $request_id; |
||
22 | |||
23 | /** |
||
24 | * Create a new builder instance |
||
25 | * |
||
26 | * @param \tbclla\Revolut\Resources\Resource $resource |
||
27 | * @param string $requestId |
||
28 | * @return void |
||
29 | */ |
||
30 | public function __construct(Buildable $resource, string $requestId = null) |
||
34 | } |
||
35 | |||
36 | /** |
||
37 | * Execute the create request |
||
38 | * |
||
39 | * @return array |
||
40 | */ |
||
41 | public function create() |
||
42 | { |
||
43 | return $this->resource->create($this->toArray()); |
||
44 | } |
||
45 | |||
46 | /** |
||
47 | * Set the unique equest ID |
||
48 | * |
||
49 | * @param string $id |
||
50 | * @return self |
||
51 | */ |
||
52 | public function requestId(string $id) |
||
53 | { |
||
54 | return $this->setAttribute('request_id', $id); |
||
55 | } |
||
56 | |||
57 | /** |
||
58 | * Set the value of an attribute |
||
59 | * |
||
60 | * @param string $attribute |
||
61 | * @param mixed $value |
||
62 | * @return self |
||
63 | */ |
||
64 | protected function setAttribute(string $attribute, $value) |
||
69 | } |
||
70 | |||
71 | /** |
||
72 | * Build the request data array |
||
73 | * |
||
74 | * @return array |
||
75 | */ |
||
76 | public function toArray() |
||
87 | } |
||
88 | } |
||
89 |