Completed
Push — master ( 111f4c...2c6dbf )
by Andrea Marco
25:17 queued 15:16
created

AbstractResource::setOption()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 6
rs 9.4285
cc 1
eloc 3
nc 1
nop 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
     * Fill the given request with the resource details.
46
     *
47
     * @param    Cerbero\FluentApi\Requests\Request    $request
48
     * @return    Cerbero\FluentApi\Requests\Request
49
     */
50
    public function fillRequest(Request $request)
51
    {
52
        return $this->request = $request->setVerb($this->getVerb())
0 ignored issues
show
Documentation Bug introduced by
It seems like $request->setVerb($this-...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...
53
                                        ->setOptions($this->getOptions())
54
                                        ->setEndpoint($this->getEndpoint());
55
    }
56
57
    /**
58
     * Retrieve the resource HTTP verb.
59
     *
60
     * @return    string
61
     */
62
    public function getVerb()
63
    {
64
        return $this->verb;
65
    }
66
67
    /**
68
     * Set the HTTP call options.
69
     *
70
     * @param    array    $options
71
     * @return    $this
72
     */
73
    public function setOptions(array $options)
74
    {
75
        $this->options = $options;
76
77
        return $this;
78
    }
79
80
    /**
81
     * Retrieve the HTTP call options.
82
     *
83
     * @return    array
84
     */
85
    public function getOptions()
86
    {
87
        return $this->options;
88
    }
89
90
    /**
91
     * Set a singular HTTP call option.
92
     *
93
     * @param    string    $option
94
     * @param    string    $value
95
     * @return    $this
96
     */
97
    public function setOption($option, $value)
98
    {
99
        $this->options[$option] = $value;
100
101
        return $this;
102
    }
103
104
    /**
105
     * Retrieve a singular HTTP call option.
106
     *
107
     * @param    string    $option
108
     * @return    mixed
109
     */
110
    public function getOption($option)
111
    {
112
        if (isset($this->options[$option])) {
113
            return $this->options[$option];
114
        }
115
116
        return null;
117
    }
118
}
119