Completed
Push — master ( 38a4e8...c04e1d )
by Vladimir
11s
created

MakesHttpRequests::post()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AcquiroPay;
6
7
trait MakesHttpRequests
8
{
9
    /** @var Api */
10
    public $api;
11
12
    /** @var string */
13
    public $serviceName;
14
15
    /**
16
     * @param string $method
17
     * @param string $uri
18
     * @param array $parameters
19
     * @return array
20
     */
21
    public function callService(string $method, string $uri, array $parameters = null): array
22
    {
23
        $data = json_decode(json_encode($this->api->callService($this->serviceName, $method, $uri, $parameters)), true);
24
25
        if (!is_array($data)) {
26
            // todo throw error?
27
            return [];
28
        }
29
30
        return $data;
31
    }
32
33
    /**
34
     * @param string $uri
35
     *
36
     * @param array|null $parameters
37
     * @return mixed
38
     */
39
    protected function get(string $uri, array $parameters = null): array
40
    {
41
        return $this->callService('GET', $uri, $parameters);
42
    }
43
44
    /**
45
     * @param string $uri
46
     * @param array|null $parameters
47
     * @return mixed
48
     */
49
    protected function post(string $uri, array $parameters = null): array
50
    {
51
        return $this->callService('POST', $uri, $parameters);
52
    }
53
54
    /**
55
     * @param string $uri
56
     * @param array|null $parameters
57
     * @return mixed
58
     */
59
    protected function put(string $uri, array $parameters = null): array
60
    {
61
        return $this->callService('PUT', $uri, $parameters);
62
    }
63
64
    /**
65
     * @param string $uri
66
     * @param array|null $parameters
67
     * @return mixed
68
     */
69
    protected function delete(string $uri, array $parameters = null): array
70
    {
71
        return $this->callService('DELETE', $uri, $parameters);
72
    }
73
}
74