Completed
Push — 4.0 ( 7855d8...1b9fbe )
by Marco
11:07
created

Status304   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 0
cbo 4
dl 0
loc 27
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A consolidate() 0 23 3
1
<?php namespace Comodojo\Dispatcher\Output\HttpStatus;
2
3
/**
4
 * Status: Not Modified
5
 *
6
 * @package     Comodojo Dispatcher
7
 * @author      Marco Giovinazzi <[email protected]>
8
 * @author      Marco Castiello <[email protected]>
9
 * @license     GPL-3.0+
10
 *
11
 * LICENSE:
12
 *
13
 * This program is free software: you can redistribute it and/or modify
14
 * it under the terms of the GNU Affero General Public License as
15
 * published by the Free Software Foundation, either version 3 of the
16
 * License, or (at your option) any later version.
17
 *
18
 * This program is distributed in the hope that it will be useful,
19
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21
 * GNU Affero General Public License for more details.
22
 *
23
 * You should have received a copy of the GNU Affero General Public License
24
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
25
 */
26
27
class Status304 extends AbstractHttpStatus {
28
29
    public function consolidate() {
0 ignored issues
show
Coding Style introduced by
consolidate 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...
30
31
        $last_modified = $this->response()->headers()->get('Last-Modified');
32
33
        if ( is_null($last_modified) ) {
34
35
            header($_SERVER["SERVER_PROTOCOL"].' 304 Not Modified');
36
37
        } else if ( is_int($last_modified) ) {
38
39
            header('Last-Modified: '.gmdate('D, d M Y H:i:s', $last_modified).' GMT', true, 304);
40
41
        } else {
42
43
            header('Last-Modified: '.$last_modified, true, 304);
44
45
        }
46
47
        header('Content-Length: '.$this->response()->content()->length());
48
49
        $this->response()->headers()->remove('Last-Modified');
0 ignored issues
show
Bug introduced by
The method remove() does not seem to exist on object<Comodojo\Dispatcher\Response\Headers>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
50
51
    }
52
53
}
54