GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

DispatcherAwareTrait::dispatchRequest()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Nip\Dispatcher;
4
5
use Nip\Http\Response\Response;
6
use Nip\Request;
7
8
/**
9
 * Class ConfigAwareTrait
10
 * @package Nip\Config
11
 */
12
trait DispatcherAwareTrait
13
{
14
    /**
15
     * @var Dispatcher|null
16
     */
17
    protected $dispatcher = null;
18
19
    /**
20
     * @param Request|null $request
21
     * @return Response|null
22
     */
23
    public function dispatchRequest(Request $request = null)
24
    {
25
        return $this->getDispatcher()->dispatch($request);
26
    }
27
28
    /**
29
     * @return Dispatcher
30
     */
31
    public function getDispatcher()
32
    {
33
        if (!$this->dispatcher) {
34
            $this->initDispatcher();
35
        }
36
37
        return $this->dispatcher;
38
    }
39
40
    /**
41
     * @param bool|Dispatcher $dispatcher
42
     * @return $this
43
     */
44
    public function setDispatcher($dispatcher = false)
45
    {
46
        $this->dispatcher = $dispatcher;
0 ignored issues
show
Documentation Bug introduced by
It seems like $dispatcher can also be of type boolean. However, the property $dispatcher is declared as type object<Nip\Dispatcher\Dispatcher>|null. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
47
48
        return $this;
49
    }
50
51
    protected function initDispatcher()
52
    {
53
        $this->setDispatcher($this->newDispatcher());
54
    }
55
56
    /**
57
     * @return Dispatcher
58
     */
59
    protected function newDispatcher()
60
    {
61
        return app()->get('dispatcher');
62
    }
63
}
64