Conditions | 4 |
Paths | 8 |
Total Lines | 16 |
Code Lines | 6 |
Lines | 0 |
Ratio | 0 % |
Tests | 0 |
CRAP Score | 20 |
Changes | 0 |
1 | <?php namespace Nimo\Traits; |
||
29 | protected function attachToRequest(ServerRequestInterface $request = null): ServerRequestInterface |
||
30 | { |
||
31 | /** |
||
32 | * @var ServerRequestInterface $request |
||
33 | */ |
||
34 | /** @noinspection PhpUndefinedFieldInspection */ |
||
35 | $request = $request ?: $this->request; |
||
|
|||
36 | |||
37 | /** @noinspection PhpUndefinedClassConstantInspection */ |
||
38 | $key = defined('static::ATTR_KEY') ? static::ATTR_KEY : static::class; |
||
39 | if ($request->getAttribute($key)) { |
||
40 | throw new \RuntimeException('middleware collision:' . $key); |
||
41 | } |
||
42 | |||
43 | return $this->request = $request->withAttribute($key, $this); |
||
44 | } |
||
45 | } |
||
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: