Completed
Push — feat/optimize-webp ( b9a7aa...68b340 )
by Arnaud
09:41 queued 09:41
created

Cwebp::canHandle()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
3
namespace Cecil\Assets\Image\Optimizers;
4
5
use Spatie\ImageOptimizer\Image;
6
use Spatie\ImageOptimizer\Optimizers\BaseOptimizer;
7
8
class Cwebp extends BaseOptimizer
9
{
10
    public $binaryName = 'cwebp';
11
12
    public function canHandle(Image $image): bool
13
    {
14
        return $image->mime() === 'image/webp';
15
    }
16
17
    public function getCommand(): string
18
    {
19
        $optionString = implode(' ', $this->options);
20
21
        return "\"{$this->binaryPath}{$this->binaryName}\" {$optionString}"
22
            .' '.escapeshellarg($this->imagePath)
23
            .' -o '.escapeshellarg($this->imagePath);
24
    }
25
}
26