| Conditions | 4 |
| Paths | 3 |
| Total Lines | 13 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 13 | private function clearDownloadDir() |
||
| 14 | { |
||
| 15 | $downloadDir = dirname(__DIR__).'/_downloads/'; |
||
| 16 | if (file_exists($downloadDir)) { |
||
| 17 | $files = scandir($downloadDir); |
||
| 18 | $files = array_filter($files, function ($fileName) use ($downloadDir) { |
||
| 19 | return is_file($downloadDir.$fileName) && (strpos($fileName, '.') != 0); |
||
| 20 | }); |
||
| 21 | foreach ($files as $f) { |
||
| 22 | unlink($downloadDir.$f); |
||
| 23 | } |
||
| 24 | } |
||
| 25 | } |
||
| 26 | |||
| 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 sub-classes 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 parent class: