OptimizeImages   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 17
c 0
b 0
f 0
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 15 2
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