Passed
Pull Request — master (#1)
by Artem
01:48
created

ImagineDriver   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 2
eloc 7
c 2
b 0
f 1
dl 0
loc 21
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A process() 0 6 1
A __construct() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ImageOptimizer;
6
7
use Imagine\Gd\Imagine;
8
use Imagine\Image\{Box, ImageInterface};
9
10
class ImagineDriver implements DriverInterface
11
{
12
    /**
13
     * @var Imagine $imagine
14
     */
15
    protected $imagine;
16
17
    public function __construct()
18
    {
19
        $this->imagine = new Imagine();
20
    }
21
22
    /**
23
     * @inheritDoc
24
     */
25
    public function process(string $path, int $width, int $height, string $resizedFile): void
26
    {
27
        $this->imagine->open($path)
28
            ->thumbnail(new Box($width, $height), ImageInterface::THUMBNAIL_OUTBOUND)
29
            ->save($resizedFile)
30
            ->save($resizedFile . '.webp');
31
    }
32
}
33