| Conditions | 2 |
| Paths | 1 |
| Total Lines | 28 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 17 | public function handle() |
||
| 18 | { |
||
| 19 | $this->comment('Start deleting old personal downloads...'); |
||
| 20 | |||
| 21 | $oldZipFiles = collect($this->getDisk()->allFiles()) |
||
| 22 | ->filter(function(string $zipFilename) { |
||
| 23 | return Str::endsWith($zipFilename, '.zip'); |
||
| 24 | }) |
||
| 25 | ->filter(function(string $zipFilename) { |
||
| 26 | $zipFilenameParts = explode('-', $zipFilename); |
||
| 27 | |||
| 28 | if (! isset($zipFilenameParts[1])) { |
||
| 29 | return false; |
||
| 30 | } |
||
| 31 | |||
| 32 | $dateCreated = Carbon::createFromTimestamp($zipFilenameParts[1]); |
||
| 33 | |||
| 34 | $threshold = now()->subDays(config('personal-data-download.delete_after_days')); |
||
| 35 | |||
| 36 | return $dateCreated->isBefore($threshold); |
||
|
|
|||
| 37 | }) |
||
| 38 | ->toArray(); |
||
| 39 | |||
| 40 | $this->getDisk()->delete($oldZipFiles); |
||
| 41 | |||
| 42 | $this->comment(count($oldZipFiles) . ' old zip files have been deleted.'); |
||
| 43 | $this->info('All done!'); |
||
| 44 | } |
||
| 45 | |||
| 50 | } |
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: