GetResourceCommand::getResourceId()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
c 0
b 0
f 0
rs 10
cc 1
eloc 1
nc 1
nop 0
1
<?php
2
3
namespace Zurbaev\ApiClient\Commands;
4
5
use Psr\Http\Message\ResponseInterface;
6
use Zurbaev\ApiClient\Contracts\ApiResourceInterface;
7
8
abstract class GetResourceCommand extends ResourceCommand
9
{
10
    /**
11
     * Resource ID.
12
     */
13
    protected $resourceId;
14
15
    /**
16
     * Determines if current command is list command.
17
     *
18
     * @return bool
19
     */
20
    protected function isListCommand(): bool
21
    {
22
        return false;
23
    }
24
25
    /**
26
     * HTTP request method.
27
     *
28
     * @return string
29
     */
30
    public function requestMethod()
31
    {
32
        return 'GET';
33
    }
34
35
    /**
36
     * Set resource ID.
37
     *
38
     * @param mixed $resourceId
39
     *
40
     * @return $this
41
     */
42
    public function setResourceId($resourceId)
43
    {
44
        $this->resourceId = $resourceId;
45
46
        return $this;
47
    }
48
49
    /**
50
     * Get resource ID.
51
     *
52
     * @return mixed
53
     */
54
    public function getResourceId()
55
    {
56
        return $this->resourceId;
57
    }
58
59
    /**
60
     * Handle command response.
61
     *
62
     * @param ResponseInterface    $response
63
     * @param ApiResourceInterface $owner
64
     *
65
     * @return mixed
66
     */
67
    public function handleResponse(ResponseInterface $response, ApiResourceInterface $owner)
68
    {
69
        $className = $this->resourceClass();
70
71
        return $className::createFromResponse($response, $owner->getApi(), $owner);
72
    }
73
74
    /**
75
     * HTTP request URL.
76
     *
77
     * @param ApiResourceInterface $resource
78
     *
79
     * @return string
80
     */
81
    public function requestUrl(ApiResourceInterface $resource)
82
    {
83
        $resourcePath = $this->resourcePath().'/'.$this->getResourceId();
84
85
        return $resource->apiUrl($resourcePath);
86
    }
87
}
88