Passed
Push — develop ( ec1e42...80559e )
by Brent
03:22
created

FixedWidthScaler::make()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Pageon\Html\Image;
4
5
use Intervention\Image\Image as ScaleableImage;
6
7
class FixedWidthScaler implements Scaler
8
{
9
    private $fixedWidths;
10
11 31
    public function __construct(array $fixedWidths)
12
    {
13 31
        $this->fixedWidths = $fixedWidths;
14 31
    }
15
16 30
    public static function make(array $fixedWidths): FixedWidthScaler
17
    {
18 30
        return new self($fixedWidths);
19
    }
20
21 12
    public function getVariations(ScaleableImage $scaleableImage): array
22
    {
23 12
        $width = $scaleableImage->getWidth();
24 12
        $height = $scaleableImage->getHeight();
25 12
        $ratio = $width / $height;
26 12
        $variations = [];
27
28 12
        foreach ($this->fixedWidths as $fixedWidth) {
29 12
            $variations[$fixedWidth] = round($fixedWidth * $ratio);
30
        }
31
32 12
        return $variations;
33
    }
34
}
35