RedirectTrait   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 10
c 1
b 0
f 0
dl 0
loc 29
ccs 0
cts 11
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A flashRedirect() 0 5 2
A redirect() 0 9 2
1
<?php
2
3
namespace Nip\Controllers\Traits;
4
5
/**
6
 * Trait NameWorksTrait
7
 * @package Nip\Controllers\Traits
8
 */
9
trait RedirectTrait
10
{
11
12
    /**
13
     * @param $message
14
     * @param $url
15
     * @param string $type
16
     * @param bool $name
17
     */
18
    protected function flashRedirect($message, $url, $type = 'success', $name = false)
19
    {
20
        $name = $name ? $name : $this->getName();
0 ignored issues
show
Bug introduced by
It seems like getName() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

20
        $name = $name ? $name : $this->/** @scrutinizer ignore-call */ getName();
Loading history...
21
        app('flash.messages')->add($name, $type, $message);
22
        $this->redirect($url);
23
    }
24
25
    /**
26
     * @param $url
27
     * @param null $code
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $code is correct as it would always require null to be passed?
Loading history...
28
     */
29
    protected function redirect($url, $code = null)
30
    {
31
        switch ($code) {
32
            case '301':
33
                header("HTTP/1.1 301 Moved Permanently");
34
                break;
35
        }
36
        header("Location: ".$url);
37
        exit();
38
    }
39
}
40