| Conditions | 4 |
| Paths | 6 |
| Total Lines | 13 |
| Code Lines | 7 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 0 |
| CRAP Score | 20 |
| Changes | 0 | ||
| 1 | <?php |
||
| 15 | public static function fromRequest(ServerRequestInterface $request) |
||
| 16 | { |
||
| 17 | /** @noinspection PhpUndefinedClassConstantInspection */ |
||
| 18 | $key = defined('static::ATTR_KEY') ? static::ATTR_KEY : static::class; |
||
| 19 | if (!$instance = $request->getAttribute($key)) { |
||
| 20 | throw new \RuntimeException('middleware not found:' . $key); |
||
| 21 | } |
||
| 22 | if (!$instance instanceof static) { |
||
| 23 | throw new \RuntimeException('middleware class error:' . $key); |
||
| 24 | } |
||
| 25 | |||
| 26 | return $instance; |
||
| 27 | } |
||
| 28 | |||
| 50 |
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: