Test Failed
Push — master ( a6b51e...5fffdb )
by Gabriel
08:05
created

RouteRegistrar::all()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
ccs 3
cts 3
cp 1
crap 1
1
<?php
2
3
namespace ByTIC\Hello\Oauth\Routes;
4
5
use ByTIC\Hello\Modules\Oauth\Controllers\KeysController;
6
use Nip\Router\Route\Route;
7
use Nip\Router\RouteCollection;
8
use Nip\Router\Router;
9
10
/**
11
 * Class RouteRegistrar
12
 * @package ByTIC\Hello\Oauth\Routes
13
 */
14
class RouteRegistrar
15
{
16
    /**
17
     * @var Router
18
     */
19
    protected $router;
20
21
    /**
22
     * @var RouteCollection
23
     */
24
    protected $routes;
25
26
    /**
27
     * RouteRegistrar constructor.
28
     * @param Router $router
29
     */
30 1
    public function __construct(Router $router)
31
    {
32 1
        $this->router = $router;
33 1
        $this->routes = $this->router->getRoutes();
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->router->getRoutes() can also be of type array<integer,object<Nip\Router\Route\Route>>. However, the property $routes is declared as type object<Nip\Router\RouteCollection>. 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...
34 1
    }
35
36 1
    public function all()
37
    {
38 1
        $this->forKeys();
39 1
    }
40
41 1
    protected function forKeys()
42
    {
43 1
        $route = new Route("/oauth/keys", ["controller" => KeysController::class, "action" => "index"]);
0 ignored issues
show
Documentation introduced by
'/oauth/keys' is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
44 1
        $route->setName('oauth.keys');
45 1
        $this->routes->prependRoute($route);
46 1
    }
47
}
48