| Conditions | 4 |
| Paths | 5 |
| Total Lines | 20 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 19 | protected function doValidation(ResponseInterface $response) |
||
| 20 | { |
||
| 21 | $document = new Document((string)$response->getBody(), false); |
||
| 22 | $urls = $document->getDependencies($response->getUri()); |
||
|
|
|||
| 23 | $invalidUrls = array(); |
||
| 24 | |||
| 25 | foreach ($urls as $url) { |
||
| 26 | if (function_exists('idn_to_ascii')) { |
||
| 27 | $idnUrl = $url->getScheme() . '://' . idn_to_ascii($url->getHost(), 0, INTL_IDNA_VARIANT_UTS46) . $url->getPath(); |
||
| 28 | } else { |
||
| 29 | $idnUrl = $url->getScheme() . '://' . $url->getHost() . $url->getPath(); |
||
| 30 | } |
||
| 31 | |||
| 32 | if (!filter_var($idnUrl, FILTER_VALIDATE_URL)) { |
||
| 33 | $invalidUrls[] = (string)$url; |
||
| 34 | } |
||
| 35 | } |
||
| 36 | |||
| 37 | $this->assert(count($invalidUrls) === 0, 'Invalid urls found (' . implode(', ', $invalidUrls) . ').'); |
||
| 38 | } |
||
| 39 | } |
||
| 40 |
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: