| Conditions | 3 |
| Paths | 2 |
| Total Lines | 12 |
| Code Lines | 8 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 23 | public function handle(SpikeInterface $message) |
||
| 24 | { |
||
| 25 | $clientId = $message->getHeader('Client-ID'); |
||
| 26 | if (!$clientId || !($client = $this->server->getClients()->findById($clientId))) { |
||
| 27 | $this->getDispatcher()->dispatch(new Event(EventStore::UNAUTHORIZED_CLIENT, $this, [ |
||
| 28 | 'clientId' => $clientId, |
||
| 29 | 'connection' => $this->connection |
||
| 30 | ])); |
||
| 31 | $this->connection->close(); |
||
| 32 | } |
||
| 33 | $this->client = $client; |
||
|
|
|||
| 34 | } |
||
| 35 | } |
If you define a variable conditionally, it can happen that it is not defined for all execution paths.
Let’s take a look at an example:
In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.
Available Fixes
Check for existence of the variable explicitly:
Define a default value for the variable:
Add a value for the missing path: