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 ( 066aef...144d73 )
by Freek
01:10
created

ImageOptimizer::setOptimizers()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 1
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 add(Optimizer $optimizer)
19
    {
20
        $this->optimizers[] = $optimizer;
21
22
        return $this;
23
    }
24
25
    public function setOptimizers(array $optimizers)
26
    {
27
        $this->optimizers = [];
28
29
        foreach($optimizers as $optimizer) {
30
            $this->add($optimizer);
31
        }
32
33
        return $this;
34
    }
35
36
    public function optimize(string $imagePath)
37
    {
38
        $mimeType = mime_content_type($imagePath);
39
40
        collect($this->optimizers)
41
            ->filter(function (Optimizer $optimizer) use ($mimeType) {
42
                return $optimizer->canHandle($mimeType);
43
            })
44
            ->each(function (Optimizer $optimizer) use ($imagePath) {
45
                $optimizer->setImagePath($imagePath);
46
47
                $process = new Process($optimizer->getCommand());
48
49
                $process->run();
50
            });
51
    }
52
53
54
}
55