Completed
Push — 4.0 ( 4d6b64...872671 )
by Marco
03:00
created

Model::getUserAgent()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 0
cts 2
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 2
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     GPL-3.0+
14
 *
15
 * LICENSE:
16
 *
17
 * This program is free software: you can redistribute it and/or modify
18
 * it under the terms of the GNU Affero General Public License as
19
 * published by the Free Software Foundation, either version 3 of the
20
 * License, or (at your option) any later version.
21
 *
22
 * This program is distributed in the hope that it will be useful,
23
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25
 * GNU Affero General Public License for more details.
26
 *
27
 * You should have received a copy of the GNU Affero General Public License
28
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
29
 */
30
31
class Model extends AbstractModel {
32
33
    use TimingTrait;
34
35 5
    public function __construct(Configuration $configuration, LoggerInterface $logger) {
0 ignored issues
show
Coding Style introduced by
__construct uses the super-global variable $_SERVER which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
36
37 5
        parent::__construct($configuration, $logger);
38
39 5
        $this->setTiming($_SERVER['REQUEST_TIME_FLOAT']);
40
41 5
        $this->setHeaders(new Headers());
42 5
        $this->setUri(HttpUri::createFromServer($_SERVER));
43 5
        $this->setPost(new Post());
44 5
        $this->setQuery(new Query());
45 5
        $this->setUserAgent(new UserAgent());
46 5
        $this->setMethod(new Method());
47 5
        $this->setVersion(new Version());
48 5
        $this->setFiles(Files::load());
49
50 5
    }
51
52
    public function getHeaders() {
53
54
        return $this->headers;
0 ignored issues
show
Bug introduced by
The property headers does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
55
56
    }
57
58 5
    public function setHeaders(Headers $headers) {
59
60 5
        $this->headers = $headers;
61
62 5
        return $this;
63
64
    }
65
66 1
    public function getUri() {
67
68 1
        return $this->uri;
0 ignored issues
show
Bug introduced by
The property uri does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
69
70
    }
71
72 5
    public function setUri(HttpUri $uri) {
73
74 5
        $this->uri = $uri;
75
76 5
        return $this;
77
78
    }
79
80
    public function getPost() {
81
82
        return $this->post;
0 ignored issues
show
Bug introduced by
The property post does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
83
84
    }
85
86 5
    public function setPost(Post $post) {
87
88 5
        $this->post = $post;
89
90 5
        return $this;
91
92
    }
93
94
    public function getQuery() {
95
96
        return $this->query;
0 ignored issues
show
Bug introduced by
The property query does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
97
98
    }
99
100 5
    public function setQuery(Query $query) {
101
102 5
        $this->query = $query;
103
104 5
        return $this;
105
106
    }
107
108
    public function getUserAgent() {
109
110
        return $this->useragent;
0 ignored issues
show
Bug introduced by
The property useragent does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
111
112
    }
113
114 5
    public function setUserAgent(UserAgent $useragent) {
115
116 5
        $this->useragent = $useragent;
117
118 5
        return $this;
119
120
    }
121
122 3
    public function getMethod() {
123
124 3
        return $this->method;
0 ignored issues
show
Bug introduced by
The property method does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
125
126
    }
127
128 5
    public function setMethod(Method $method) {
129
130 5
        $this->method = $method;
131
132 5
        return $this;
133
134
    }
135
136 4
    public function getVersion() {
137
138 4
        return $this->version;
0 ignored issues
show
Bug introduced by
The property version does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
139
140
    }
141
142 5
    public function setVersion(Version $version) {
143
144 5
        $this->version = $version;
145
146 5
        return $this;
147
148
    }
149
150
    public function getFiles() {
151
152
        return $this->files;
0 ignored issues
show
Bug introduced by
The property files does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
153
154
    }
155
156 5
    public function setFiles(array $files) {
157
158 5
        $this->files = $files;
159
160 5
        return $this;
161
162
    }
163
164 1
    public function route() {
165
166 1
        return str_replace($this->getConfiguration()->get("base-uri"), "", $this->getUri()->getPath());
167
168
    }
169
170
}
171