Passed
Push — master ( 26a73e...e9f82c )
by Brent
03:12
created

WidthScaler::scale()   B

Complexity

Conditions 7
Paths 6

Size

Total Lines 20
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 20
rs 8.2222
c 0
b 0
f 0
cc 7
eloc 12
nc 6
nop 2
1
<?php
2
3
namespace Brendt\Image\Scaler;
4
5
use Intervention\Image\Image;
6
use Symfony\Component\Finder\SplFileInfo;
7
8
class WidthScaler extends AbstractScaler
9
{
10
11
    /**
12
     * @param SplFileInfo $sourceFile
13
     * @param Image       $imageObject
14
     *
15
     * @return array
16
     */
17
    public function scale(SplFileInfo $sourceFile, Image $imageObject) : array {
18
        $width = $imageObject->getWidth();
19
        $height = $imageObject->getHeight();
20
        $sizes = [];
21
22
        if ($this->includeSource && (!$this->maxWidth || $width <= $this->maxWidth)) {
23
            $sizes[$width] = $height;
24
        }
25
26
        while ($width >= $this->minWidth) {
27
            $width = floor($width * $this->stepModifier);
28
            $height = floor($height * $this->stepModifier);
29
30
            if (!$this->maxWidth || $width <= $this->maxWidth) {
31
                $sizes[(int) $width] = $height;
32
            }
33
        }
34
35
        return $sizes;
36
    }
37
}
38