| Conditions | 3 |
| Paths | 1 |
| Total Lines | 17 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 8 |
| CRAP Score | 3.072 |
| Changes | 0 | ||
| 1 | <?php |
||
| 14 | public function register() |
||
| 15 | { |
||
| 16 | 1 | $this->getContainer()->share(Client::class, function () { |
|
|
|
|||
| 17 | $headers = [ |
||
| 18 | 1 | 'transfer-encoding' => 'chunked', |
|
| 19 | ]; |
||
| 20 | 1 | if (array_key_exists('HTTP_X_REAL_IP', $_SERVER)) { |
|
| 21 | $headers['x-real-ip'] = $_SERVER['HTTP_X_REAL_IP']; |
||
| 22 | } |
||
| 23 | 1 | if (array_key_exists('HTTP_X_SESSION', $_SERVER)) { |
|
| 24 | $headers['x-session'] = $_SERVER['HTTP_X_SESSION']; |
||
| 25 | } |
||
| 26 | 1 | return new Client([ |
|
| 27 | 1 | 'headers' => $headers |
|
| 28 | ]); |
||
| 29 | 1 | }); |
|
| 30 | 1 | } |
|
| 31 | } |
||
| 32 |
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the interface: