Completed
Push — 4.0 ( 954171...ed2d0a )
by Marco
13:55
created

Model::useragent()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 5
rs 9.4286
cc 1
eloc 2
nc 1
nop 0
1
<?php namespace Comodojo\Dispatcher\Request;
2
3
use \Comodojo\Components\Model as DispatcherClassModel;
4
use \League\Uri\Schemes\Http as HttpUri;
5
use \Comodojo\Dispatcher\Request\Headers;
6
use \Comodojo\Dispatcher\Request\Post;
7
use \Comodojo\Dispatcher\Request\UserAgent;
8
use \Comodojo\Dispatcher\Request\Method;
9
use \Comodojo\Dispatcher\Components\Timestamp as TimestampTrait;
10
11
/**
12
 *
13
 * @package     Comodojo dispatcher
14
 * @author      Marco Giovinazzi <[email protected]>
15
 * @license     GPL-3.0+
16
 *
17
 * LICENSE:
18
 *
19
 * This program is free software: you can redistribute it and/or modify
20
 * it under the terms of the GNU Affero General Public License as
21
 * published by the Free Software Foundation, either version 3 of the
22
 * License, or (at your option) any later version.
23
 *
24
 * This program is distributed in the hope that it will be useful,
25
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
27
 * GNU Affero General Public License for more details.
28
 *
29
 * You should have received a copy of the GNU Affero General Public License
30
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
31
 */
32
33
class Model extends DispatcherClassModel {
34
35
    use TimestampTrait;
36
37
    private $headers = null;
38
39
    private $uri = null;
40
41
    private $useragent = null;
42
43
    private $post = null;
44
45
    private $method = null;
46
47
    public function __construct(Configuration $configuration, Logger $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...
48
49
        parent::__construct($configuration, $logger);
50
51
        $this->setTimestamp($_SERVER['REQUEST_TIME_FLOAT']);
52
53
        $this->headers = new Headers();
54
55
        $this->uri = HttpUri::createFromServer($_SERVER);
56
57
        $this->post = new Post();
58
59
        $this->useragent = new UserAgent();
60
61
        $this->method = new Method();
62
63
    }
64
65
    public function headers() {
66
67
        return $this->headers;
68
69
    }
70
71
    public function uri() {
72
73
        return $this->uri;
74
75
    }
76
77
    public function post() {
78
79
        return $this->post;
80
81
    }
82
83
    public function useragent() {
84
85
        return $this->useragent;
86
87
    }
88
89
    public function method() {
90
91
        return $this->method;
92
    }
93
94
}
95