Action::getEndpoint()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
namespace ShopifyClient\Action;
4
5
use ShopifyClient\Exception\ClientException;
6
7
class Action implements ActionInterface
8
{
9
    /**
10
     * @var string
11
     */
12
    private $method;
13
14
    /**
15
     * @var array
16
     */
17
    private $validMethods = [
18
        'GET',
19
        'POST',
20
        'PUT',
21
        'DELETE',
22
    ];
23
24
    /**
25
     * @var string
26
     */
27
    private $endpoint;
28
29
    /**
30
     * @var string|null
31
     */
32
    private $resourceKey;
33
34
    /**
35
     * @var string|null
36
     */
37
    private $responseKey;
38
39
    /**
40
     * Action constructor.
41
     * @param string $method
42
     * @param string $endpoint
43
     * @param string|null $responseKey
44
     * @param string|null $resourceKey
45
     */
46 6
    public function __construct(
47
        string $method,
48
        string $endpoint,
49
        string $responseKey = null,
50
        string $resourceKey = null
51
    ) {
52 6
        $this->setMethod($method);
53 5
        $this->setEndpoint($endpoint);
54 5
        $this->setResponseKey($responseKey);
55 5
        $this->setResourceKey($resourceKey);
56 5
    }
57
58
    /**
59
     * @return string
60
     */
61 130
    public function getMethod()
62
    {
63 130
        return $this->method;
64
    }
65
66
    /**
67
     * @return string
68
     */
69 130
    public function getEndpoint()
70
    {
71 130
        return $this->endpoint;
72
    }
73
74
    /**
75
     * @return string|null
76
     */
77 130
    public function getResourceKey()
78
    {
79 130
        return $this->resourceKey;
80
    }
81
82
    /**
83
     * @return string|null
84
     */
85 130
    public function getResponseKey()
86
    {
87 130
        return $this->responseKey;
88
    }
89
90
    /**
91
     * @param string $method
92
     * @throws ClientException
93
     */
94 6
    private function setMethod(string $method)
95
    {
96 6
        if (!in_array($method, $this->validMethods)) {
97 1
            throw new ClientException(
98 1
                sprintf(
99 1
                    'Only the following methods are allowed: %s',
100 1
                    implode(
101 1
                        ',',
102 1
                        $this->validMethods
103
                    )
104
                )
105
            );
106
        }
107
108 5
        $this->method = $method;
109 5
    }
110
111
    /**
112
     * @param string $endpoint
113
     */
114 5
    private function setEndpoint(string $endpoint)
115
    {
116 5
        $this->endpoint = $endpoint;
117 5
    }
118
119
    /**
120
     * @param string|null $resourceKey
121
     */
122 5
    private function setResourceKey(string $resourceKey = null)
123
    {
124 5
        $this->resourceKey = $resourceKey;
125 5
    }
126
127
    /**
128
     * @param string|null $responseKey
129
     */
130 5
    private function setResponseKey(string $responseKey = null)
131
    {
132 5
        $this->responseKey = $responseKey;
133 5
    }
134
}
135