AbstractResource   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 119
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 5
Bugs 1 Features 1
Metric Value
wmc 9
lcom 1
cbo 2
dl 0
loc 119
rs 10
c 5
b 1
f 1

9 Methods

Rating   Name   Duplication   Size   Complexity  
getEndpoint() 0 1 ?
A getRequest() 0 4 1
A updateOptions() 0 4 1
A fillRequest() 0 6 1
A getVerb() 0 4 1
A setOptions() 0 6 1
A getOptions() 0 4 1
A setOption() 0 6 1
A getOption() 0 8 2
1
<?php
2
3
namespace Cerbero\FluentApi;
4
5
use Cerbero\FluentApi\Requests\Request;
6
7
/**
8
 * Abstract implementation of an API resource.
9
 *
10
 */
11
abstract class AbstractResource extends VersionableRequestMaker
12
{
13
    /**
14
     * The resource HTTP verb.
15
     *
16
     * @var string|null
17
     */
18
    protected $verb;
19
20
    /**
21
     * The HTTP call options.
22
     *
23
     * @var array
24
     */
25
    protected $options = [];
26
27
    /**
28
     * Retrieve the resource endpoint.
29
     *
30
     * @return    string
31
     */
32
    abstract public function getEndpoint();
33
34
    /**
35
     * Retrieve the request to pass through resources.
36
     *
37
     * @return    Cerbero\FluentApi\Requests\Request
38
     */
39
    public function getRequest()
40
    {
41
        return $this->request;
42
    }
43
44
    /**
45
     * Update the given request with the resource options.
46
     *
47
     * @param    Cerbero\FluentApi\Requests\Request    $request
48
     * @return    Cerbero\FluentApi\Requests\Request
49
     */
50
    public function updateOptions(Request $request)
51
    {
52
        return $this->request = $request->setOptions($this->getOptions());
0 ignored issues
show
Documentation Bug introduced by
It seems like $request->setOptions($this->getOptions()) of type object<Cerbero\FluentApi\Requests\Request> is incompatible with the declared type object<Cerbero\FluentApi...ntApi\Requests\Request> of property $request.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
53
    }
54
55
    /**
56
     * Fill the given request with the resource details.
57
     *
58
     * @param    Cerbero\FluentApi\Requests\Request    $request
59
     * @return    Cerbero\FluentApi\Requests\Request
60
     */
61
    public function fillRequest(Request $request)
62
    {
63
        return $this->request = $this->updateOptions($request)
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->updateOptions($re...t($this->getEndpoint()) of type object<Cerbero\FluentApi\Requests\Request> is incompatible with the declared type object<Cerbero\FluentApi...ntApi\Requests\Request> of property $request.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
64
                                     ->setVerb($this->getVerb())
65
                                     ->setEndpoint($this->getEndpoint());
66
    }
67
68
    /**
69
     * Retrieve the resource HTTP verb.
70
     *
71
     * @return    string
72
     */
73
    public function getVerb()
74
    {
75
        return $this->verb;
76
    }
77
78
    /**
79
     * Set the HTTP call options.
80
     *
81
     * @param    array    $options
82
     * @return    $this
83
     */
84
    public function setOptions(array $options)
85
    {
86
        $this->options = array_merge_recursive($this->getOptions(), $options);
87
88
        return $this;
89
    }
90
91
    /**
92
     * Retrieve the HTTP call options.
93
     *
94
     * @return    array
95
     */
96
    public function getOptions()
97
    {
98
        return $this->options;
99
    }
100
101
    /**
102
     * Set a singular HTTP call option.
103
     *
104
     * @param    string    $option
105
     * @param    mixed    $value
106
     * @return    $this
107
     */
108
    public function setOption($option, $value)
109
    {
110
        $this->options[$option] = $value;
111
112
        return $this;
113
    }
114
115
    /**
116
     * Retrieve a singular HTTP call option.
117
     *
118
     * @param    string    $option
119
     * @return    mixed
120
     */
121
    public function getOption($option)
122
    {
123
        if (isset($this->options[$option])) {
124
            return $this->options[$option];
125
        }
126
127
        return null;
128
    }
129
}
130