Redirect   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 0
dl 0
loc 34
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A to() 0 4 1
A back() 0 4 1
A createRedirect() 0 4 1
1
<?php
2
3
namespace Vertex\Core;
4
5
class Redirect
6
{
7
    /**
8
     * Redirect to the specified url.
9
     * 
10
     * @param  string $url 
11
     * @return void
12
     */
13
    public static function to($url)
14
    {
15
	self::createRedirect($url);
16
    }
17
18
    /**
19
     * Redirect to the previous url.
20
     * 
21
     * @return void
22
     */
23
    public static function back()
0 ignored issues
show
Coding Style introduced by
back 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...
24
    {
25
        self::createRedirect($_SERVER['HTTP_REFERER']);
26
    }
27
28
    /**
29
     * Create a new redirect.
30
     * 
31
     * @param  string $location 
32
     * @return void
33
     */
34
    public static function createRedirect($location)
35
    {
36
        header('location:' . $location);
37
    }
38
}
39