| Conditions | 3 |
| Paths | 3 |
| Total Lines | 19 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 27 | protected function doValidation(ResponseInterface $response) |
||
| 28 | { |
||
| 29 | $document = new Document((string)$response->getBody()); |
||
| 30 | $images = $document->getImages($response->getUri()); |
||
|
|
|||
| 31 | |||
| 32 | $foreignImages = array(); |
||
| 33 | |||
| 34 | /* @var $currentUri Uri */ |
||
| 35 | $currentUri = $response->getUri(); |
||
| 36 | |||
| 37 | foreach ($images as $image) { |
||
| 38 | /* @var $image Uri */ |
||
| 39 | if ($currentUri->getHost($this->depth) !== $image->getHost($this->depth)) { |
||
| 40 | $foreignImages[] = (string)$image; |
||
| 41 | } |
||
| 42 | } |
||
| 43 | |||
| 44 | $this->assert(count($foreignImages) === 0, 'Images from a foreign domain where found (' . implode(', ', $foreignImages) . ')'); |
||
| 45 | } |
||
| 46 | } |
||
| 47 |
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: