Model::setVersion()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 5
c 0
b 0
f 0
ccs 3
cts 3
cp 1
rs 10
cc 1
nc 1
nop 1
crap 1
1
<?php namespace Comodojo\Dispatcher\Request;
2
3
use \Comodojo\Dispatcher\Components\AbstractModel;
4
use \Comodojo\Foundation\Timing\TimingTrait;
5
use \Comodojo\Foundation\Base\Configuration;
6
use \League\Uri\Schemes\Http as HttpUri;
7
use \Psr\Log\LoggerInterface;
8
9
/**
10
 * @package     Comodojo Dispatcher
11
 * @author      Marco Giovinazzi <[email protected]>
12
 * @author      Marco Castiello <[email protected]>
13
 * @license     MIT
14
 *
15
 * LICENSE:
16
 *
17
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23
 * THE SOFTWARE.
24
 */
25
26
class Model extends AbstractModel {
27
28
    use TimingTrait;
29
30
    protected $headers;
31
32
    protected $uri;
33
34
    protected $post;
35
36
    protected $query;
37
38
    protected $useragent;
39
40
    protected $method;
41
42
    protected $version;
43
44
    protected $files;
45
46 7
    public function __construct(Configuration $configuration, LoggerInterface $logger) {
47
48 7
        parent::__construct($configuration, $logger);
49
50 7
        $this->setTiming($_SERVER['REQUEST_TIME_FLOAT']);
51
52 7
        $this->setHeaders(new Headers());
53 7
        $this->setUri(HttpUri::createFromServer($_SERVER));
54 7
        $this->setPost(new Post());
55 7
        $this->setQuery(new Query());
56 7
        $this->setUserAgent(new UserAgent());
57 7
        $this->setMethod(new Method());
58 7
        $this->setVersion(new Version());
59 7
        $this->setFiles(Files::load());
60
61 7
    }
62
63
    public function getHeaders() {
64
65
        return $this->headers;
66
67
    }
68
69 7
    public function setHeaders(Headers $headers) {
70
71 7
        $this->headers = $headers;
72
73 7
        return $this;
74
75
    }
76
77 3
    public function getUri() {
78
79 3
        return $this->uri;
80
81
    }
82
83 7
    public function setUri(HttpUri $uri) {
84
85 7
        $this->uri = $uri;
86
87 7
        return $this;
88
89
    }
90
91
    public function getPost() {
92
93
        return $this->post;
94
95
    }
96
97 7
    public function setPost(Post $post) {
98
99 7
        $this->post = $post;
100
101 7
        return $this;
102
103
    }
104
105
    public function getQuery() {
106
107
        return $this->query;
108
109
    }
110
111 7
    public function setQuery(Query $query) {
112
113 7
        $this->query = $query;
114
115 7
        return $this;
116
117
    }
118
119
    public function getUserAgent() {
120
121
        return $this->useragent;
122
123
    }
124
125 7
    public function setUserAgent(UserAgent $useragent) {
126
127 7
        $this->useragent = $useragent;
128
129 7
        return $this;
130
131
    }
132
133 5
    public function getMethod() {
134
135 5
        return $this->method;
136
137
    }
138
139 7
    public function setMethod(Method $method) {
140
141 7
        $this->method = $method;
142
143 7
        return $this;
144
145
    }
146
147 4
    public function getVersion() {
148
149 4
        return $this->version;
150
151
    }
152
153 7
    public function setVersion(Version $version) {
154
155 7
        $this->version = $version;
156
157 7
        return $this;
158
159
    }
160
161
    public function getFiles() {
162
163
        return $this->files;
164
165
    }
166
167 7
    public function setFiles(array $files) {
168
169 7
        $this->files = $files;
170
171 7
        return $this;
172
173
    }
174
175 1
    public function route() {
176
177 1
        return str_replace($this->getConfiguration()->get("base-location"), "", $this->getUri()->getPath());
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
Coding Style Comprehensibility introduced by
The string literal base-location does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
178
179
    }
180
181
}
182