1 | <?php |
||||||
2 | |||||||
3 | namespace Nip\Router; |
||||||
4 | |||||||
5 | use Nip\Request; |
||||||
6 | |||||||
7 | /** |
||||||
8 | * Class ConfigAwareTrait |
||||||
9 | * @package Nip\Router |
||||||
10 | */ |
||||||
11 | trait RouterAwareTrait |
||||||
12 | { |
||||||
13 | /** |
||||||
14 | * @var Router|null |
||||||
15 | */ |
||||||
16 | protected $router = null; |
||||||
17 | |||||||
18 | /** |
||||||
19 | * @param bool|Request $request |
||||||
20 | * @return array |
||||||
21 | */ |
||||||
22 | public function route($request = false) |
||||||
23 | { |
||||||
24 | $request = $request ? $request : $this->getRequest(); |
||||||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||||||
25 | |||||||
26 | $router = $this->getRouter(); |
||||||
27 | $router->setContext((new RequestContext())->fromRequest($this->getRequest())); |
||||||
28 | |||||||
29 | $params = $router->route($request); |
||||||
0 ignored issues
–
show
The function
Nip\Router\Router::route() has been deprecated: Use matchRequest($request)
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This function has been deprecated. The supplier of the function has supplied an explanatory message. The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead. ![]() It seems like
$request can also be of type true ; however, parameter $request of Nip\Router\Router::route() does only seem to accept Nip\Request|Psr\Http\Mes...\ServerRequestInterface , maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
30 | |||||||
31 | return $params; |
||||||
32 | } |
||||||
33 | |||||||
34 | /** |
||||||
35 | * @return Router |
||||||
36 | */ |
||||||
37 | public function getRouter() |
||||||
38 | { |
||||||
39 | if (!$this->router) { |
||||||
40 | $this->initRouter(); |
||||||
41 | } |
||||||
42 | |||||||
43 | return $this->router; |
||||||
44 | } |
||||||
45 | |||||||
46 | /** |
||||||
47 | * @param Router $router |
||||||
48 | * @return $this |
||||||
49 | */ |
||||||
50 | public function setRouter($router = false) |
||||||
51 | { |
||||||
52 | $this->router = $router; |
||||||
0 ignored issues
–
show
It seems like
$router can also be of type false . However, the property $router is declared as type Nip\Router\Router|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 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;
}
![]() |
|||||||
53 | |||||||
54 | return $this; |
||||||
55 | } |
||||||
56 | |||||||
57 | protected function initRouter() |
||||||
58 | { |
||||||
59 | $this->setRouter($this->newRouter()); |
||||||
60 | } |
||||||
61 | |||||||
62 | /** |
||||||
63 | * @return Router |
||||||
64 | */ |
||||||
65 | protected function newRouter() |
||||||
66 | { |
||||||
67 | return app()->get('router'); |
||||||
68 | } |
||||||
69 | } |
||||||
70 |