TRedirectHelpers::redirectTo()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 2
eloc 6
c 1
b 0
f 1
nc 2
nop 1
dl 0
loc 9
rs 9.6666
1
<?php
2
3
namespace Anax\MVC;
4
5
/**
6
 * Helpers for redirecting to other pages and controllers.
7
 *
8
 */
9
trait TRedirectHelpers
10
{
11
12
    /**
13
     * Redirect to current or another route.
14
     *
15
     * @param string $route the route to redirect to, 
16
     * null to redirect to current route, "" to redirect to baseurl.
17
     *
18
     * @return void
19
     */
20
    public function redirectTo($route = null)
21
    {
22
        if (is_null($route)) {
23
            $url = $this->di->request->getCurrentUrl();
0 ignored issues
show
Bug introduced by
The property di 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...
24
        } else {
25
            $url = $this->di->url->create($route);
26
        }
27
        $this->di->response->redirect($url);
28
    }
29
}
30