TRedirectHelpers   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 21
ccs 0
cts 7
cp 0
rs 10
c 0
b 0
f 0
wmc 2
lcom 1
cbo 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A redirectTo() 0 9 2
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