ResourceCommand   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
dl 0
loc 58
c 0
b 0
f 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A command() 0 3 1
A requestUrl() 0 5 1
A isListCommand() 0 3 1
1
<?php
2
3
namespace Zurbaev\ApiClient\Commands;
4
5
use Zurbaev\ApiClient\Contracts\ApiResourceInterface;
6
use Psr\Http\Message\ResponseInterface;
7
8
abstract class ResourceCommand extends ApiCommand
9
{
10
    /**
11
     * Resource path.
12
     *
13
     * @return string
14
     */
15
    abstract public function resourcePath();
16
17
    /**
18
     * Resource class name.
19
     *
20
     * @return string
21
     */
22
    abstract public function resourceClass();
23
24
    /**
25
     * Handle command response.
26
     *
27
     * @param ResponseInterface    $response
28
     * @param ApiResourceInterface $owner
29
     *
30
     * @return mixed
31
     */
32
    abstract public function handleResponse(ResponseInterface $response, ApiResourceInterface $owner);
33
34
    /**
35
     * Determines if current command is list command.
36
     *
37
     * @return bool
38
     */
39
    protected function isListCommand(): bool
40
    {
41
        return false;
42
    }
43
44
    /**
45
     * Command name.
46
     *
47
     * @return string
48
     */
49
    public function command()
50
    {
51
        return $this->resourcePath();
52
    }
53
54
    /**
55
     * HTTP request URL.
56
     *
57
     * @param ApiResourceInterface $resource
58
     *
59
     * @return string
60
     */
61
    public function requestUrl(ApiResourceInterface $resource)
62
    {
63
        $resourcePath = $this->resourcePath();
64
65
        return $resource->apiUrl($resourcePath);
66
    }
67
}
68