Passed
Push — dependabot/npm_and_yarn/string... ( b56eb5...bc569b )
by
unknown
45:46 queued 33s
created

OptimizeImages   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 17
ccs 0
cts 8
cp 0
rs 10
c 0
b 0
f 0
wmc 2
1
<?php
2
3
namespace Thinktomorrow\Chief\App\Http\Middleware;
4
5
use Closure;
6
use Spatie\ImageOptimizer\OptimizerChain;
7
use Symfony\Component\HttpFoundation\File\UploadedFile;
8
9
class OptimizeImages
10
{
11
    public function handle($request, Closure $next)
12
    {
13
        $optimizerChain = app(OptimizerChain::class);
14
15
        collect($request->allFiles())->each(function ($file) use ($optimizerChain) {
16
            if (is_array($file)) {
17
                collect($file)->each(function ($media) use ($optimizerChain) {
18
                    $optimizerChain->optimize($media->getPathname());
19
                });
20
            } else {
21
                $optimizerChain->optimize($file->getPathname());
22
            }
23
        });
24
25
        return $next($request);
26
    }
27
}
28