OptimizeImages::handle()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 8
nc 1
nop 2
dl 0
loc 15
c 0
b 0
f 0
cc 2
rs 10
1
<?php
2
3
namespace Thinktomorrow\Chief\App\Http\Middleware;
4
5
use Closure;
6
use Spatie\ImageOptimizer\OptimizerChain;
7
8
class OptimizeImages
9
{
10
    public function handle($request, Closure $next)
11
    {
12
        $optimizerChain = app(OptimizerChain::class);
13
14
        collect($request->allFiles())->each(function ($file) use ($optimizerChain) {
15
            if (is_array($file)) {
16
                collect($file)->each(function ($media) use ($optimizerChain) {
0 ignored issues
show
Bug introduced by
$file of type array is incompatible with the type Illuminate\Contracts\Support\Arrayable expected by parameter $value of collect(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

16
                collect(/** @scrutinizer ignore-type */ $file)->each(function ($media) use ($optimizerChain) {
Loading history...
17
                    $optimizerChain->optimize($media->getPathname());
18
                });
19
            } else {
20
                $optimizerChain->optimize($file->getPathname());
21
            }
22
        });
23
24
        return $next($request);
25
    }
26
}
27