Conditions | 6 |
Paths | 6 |
Total Lines | 25 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
26 | protected function doValidation(ResponseInterface $response) |
||
27 | { |
||
28 | $bigFiles = []; |
||
29 | |||
30 | if ($response instanceof ResourcesAwareResponse) { |
||
31 | foreach ($response->getResources() as $resource) { |
||
32 | $resourceSize = round($resource['transferSize'] / 1000); |
||
33 | |||
34 | if ($resourceSize > $this->maxElementSize) { |
||
35 | $bigFiles[] = ['name' => $resource['name'], 'size' => $resourceSize]; |
||
36 | } |
||
37 | } |
||
38 | } |
||
39 | |||
40 | if (count($bigFiles) > 0) { |
||
41 | $message = "Some files were found that are too big (max: " . $this->maxElementSize . " KB):<ul>"; |
||
42 | foreach ($bigFiles as $bigFile) { |
||
43 | $message .= '<li>File: ' . $bigFile['name'] . ', Size: ' . $bigFile['size'] . ' KB</li>'; |
||
44 | } |
||
45 | $message .= "</ul>"; |
||
46 | $result = new CheckResult(CheckResult::STATUS_FAILURE, $message, count($bigFiles)); |
||
47 | $result->addAttribute(new Attribute('resources', $response->getResources(), true)); |
||
|
|||
48 | return $result; |
||
49 | } |
||
50 | } |
||
51 | } |
||
52 |
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: