Request   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 118
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

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

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A setVerb() 0 6 1
A verb() 0 4 1
A setEndpoint() 0 8 1
A normalizeEndpoint() 0 6 2
A endpoint() 0 4 1
A setOptions() 0 6 1
A options() 0 4 1
1
<?php
2
3
namespace Cerbero\FluentApi\Requests;
4
5
/**
6
 * Resource request.
7
 *
8
 */
9
class Request implements RequestInterface
10
{
11
    /**
12
     * The HTTP verb.
13
     *
14
     * @var string
15
     */
16
    protected $verb;
17
18
    /**
19
     * The endpoint.
20
     *
21
     * @var string
22
     */
23
    protected $endpoint;
24
25
    /**
26
     * The options.
27
     *
28
     * @var array
29
     */
30
    protected $options = [];
31
32
    /**
33
     * Set the base API URL.
34
     *
35
     * @param    string    $url
36
     * @return    void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
37
     */
38
    public function __construct($url)
39
    {
40
        $this->setEndpoint($url);
41
    }
42
43
    /**
44
     * Set the HTTP verb.
45
     *
46
     * @param    string    $verb
47
     * @return    $this
48
     */
49
    public function setVerb($verb)
50
    {
51
        $this->verb = $verb;
52
53
        return $this;
54
    }
55
56
    /**
57
     * Retrieve the HTTP verb.
58
     *
59
     * @return    string
60
     */
61
    public function verb()
62
    {
63
        return $this->verb;
64
    }
65
66
    /**
67
     * Set the endpoint.
68
     *
69
     * @param    string    $endpoint
70
     * @return    $this
71
     */
72
    public function setEndpoint($endpoint)
73
    {
74
        $this->normalizeEndpoint($endpoint);
75
76
        $this->endpoint = $endpoint;
77
78
        return $this;
79
    }
80
81
    /**
82
     * Normalize the API endpoint.
83
     *
84
     * @param    string    $endpoint
85
     * @return    void
86
     */
87
    private function normalizeEndpoint(&$endpoint)
88
    {
89
        if ($url = $this->endpoint()) {
90
            $endpoint = rtrim($url, '/') . '/' . ltrim($endpoint, '/');
91
        }
92
    }
93
94
    /**
95
     * Retrieve the endpoint.
96
     *
97
     * @return    string
98
     */
99
    public function endpoint()
100
    {
101
        return $this->endpoint;
102
    }
103
104
    /**
105
     * Set the options.
106
     *
107
     * @param    array    $options
108
     * @return    $this
109
     */
110
    public function setOptions(array $options)
111
    {
112
        $this->options = array_merge_recursive($this->options(), $options);
113
114
        return $this;
115
    }
116
117
    /**
118
     * Retrieve the options.
119
     *
120
     * @return    array
121
     */
122
    public function options()
123
    {
124
        return $this->options;
125
    }
126
}
127