FixedWidthScaler::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 4
ccs 3
cts 3
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 4
    public function __construct(array $fixedWidths)
12
    {
13 4
        $this->fixedWidths = $fixedWidths;
14 4
    }
15
16 4
    public static function make(array $fixedWidths): FixedWidthScaler
17
    {
18 4
        return new self($fixedWidths);
19
    }
20
21 4
    public function getVariations(ScaleableImage $scaleableImage): array
22
    {
23 4
        $width = $scaleableImage->getWidth();
24 4
        $height = $scaleableImage->getHeight();
25 4
        $ratio = $width / $height;
26 4
        $variations = [];
27
28 4
        foreach ($this->fixedWidths as $fixedWidth) {
29 4
            $variations[$fixedWidth] = round($fixedWidth * $ratio);
30
        }
31
32 4
        return $variations;
33
    }
34
}
35