HasPreviousUrlTrait::previous()   A
last analyzed

Complexity

Conditions 4
Paths 6

Size

Total Lines 10
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 4
eloc 8
nc 6
nop 1
dl 0
loc 10
rs 10
c 1
b 0
f 1
ccs 0
cts 8
cp 0
crap 20
1
<?php
2
3
namespace Nip\Router\Generator\Traits;
4
5
use Nip\Router\RequestContext;
6
7
/**
8
 * Trait HasPreviousUrlTrait
9
 * @package Nip\Router\Generator\Traits
10
 * @method RequestContext getContext()
11
 */
12
trait HasPreviousUrlTrait
13
{
14
15
    /**
16
     * Get the URL for the previous request.
17
     *
18
     * @param  mixed $fallback
19
     * @return string
20
     */
21
    public function previous($fallback = false)
22
    {
23
        $referrer = $this->getContext()->getHeaders()->get('referer');
24
        $url = $referrer ? $this->to($referrer) : $this->getPreviousUrlFromSession();
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->getPreviousUrlFromSession() targeting Nip\Router\Generator\Tra...reviousUrlFromSession() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
Bug introduced by
It seems like to() 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

24
        $url = $referrer ? $this->/** @scrutinizer ignore-call */ to($referrer) : $this->getPreviousUrlFromSession();
Loading history...
25
        if ($url) {
26
            return $url;
27
        } elseif ($fallback) {
28
            return $this->to($fallback);
29
        } else {
30
            return $this->to('/');
31
        }
32
    }
33
34
    /**
35
     * Get the previous URL from the session if possible.
36
     *
37
     * @return string|null
38
     */
39
    protected function getPreviousUrlFromSession()
40
    {
41
        return null;
42
//        $session = $this->getSession();
43
//        return $session ? $session->previousUrl() : null;
44
    }
45
}
46