Conditions | 4 |
Paths | 6 |
Total Lines | 13 |
Code Lines | 7 |
Lines | 0 |
Ratio | 0 % |
Tests | 0 |
CRAP Score | 20 |
Changes | 0 |
1 | <?php namespace Nimo\Traits; |
||
11 | public static function fromRequest(ServerRequestInterface $request): self |
||
12 | { |
||
13 | /** @noinspection PhpUndefinedClassConstantInspection */ |
||
14 | $key = defined('static::ATTR_KEY') ? static::ATTR_KEY : static::class; |
||
15 | if (!$instance = $request->getAttribute($key)) { |
||
16 | throw new \RuntimeException('middleware not found:' . $key); |
||
17 | } |
||
18 | if (!$instance instanceof static) { |
||
19 | throw new \RuntimeException('middleware class error:' . $key); |
||
20 | } |
||
21 | |||
22 | return $instance; |
||
23 | } |
||
24 | |||
46 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: