GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 8e439c...066aef )
by Freek
01:02
created

ImageOptimizer::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Spatie\ImageOptimizer;
4
5
use Symfony\Component\Process\Process;
6
use Spatie\ImageOptimizer\Optimizers\Jpegoptim;
7
use Spatie\ImageOptimizer\Optimizers\Optimizer;
8
9
class ImageOptimizer
10
{
11
    public $optimizers = [];
12
13
    public function __construct()
14
    {
15
        $this->add(new Jpegoptim());
16
    }
17
18
    public function optimize(string $imagePath)
19
    {
20
        $mimeType = mime_content_type($imagePath);
21
22
        collect($this->optimizers)
23
            ->filter(function (Optimizer $optimizer) use ($mimeType) {
24
                return $optimizer->canHandle($mimeType);
25
            })
26
            ->each(function (Optimizer $optimizer) use ($imagePath) {
27
                $optimizer->setImagePath($imagePath);
28
29
                $process = new Process($optimizer->getCommand());
30
31
                $process->run();
32
            });
33
    }
34
35
    public function add(Optimizer $optimizer)
36
    {
37
        $this->optimizers[] = $optimizer;
38
    }
39
}
40