RedirectTrait::flashRedirect()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 5
ccs 0
cts 4
cp 0
rs 10
cc 2
nc 2
nop 4
crap 6
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