Background::run()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
dl 0
loc 16
ccs 0
cts 13
cp 0
rs 9.7333
c 0
b 0
f 0
cc 3
nc 3
nop 1
crap 12
1
<?php
2
3
namespace League\Glide\Manipulators;
4
5
use Intervention\Image\Image;
6
use League\Glide\Manipulators\Helpers\Color;
7
8
/**
9
 * @property string $bg
10
 */
11
class Background extends BaseManipulator
12
{
13
    /**
14
     * Perform background image manipulation.
15
     * @param  Image $image The source image.
16
     * @return Image The manipulated image.
17
     */
18
    public function run(Image $image)
19
    {
20
        if (is_null($this->bg)) {
21
            return $image;
22
        }
23
24
        $color = (new Color($this->bg))->formatted();
25
26
        if ($color) {
27
            $new = $image->getDriver()->newImage($image->width(), $image->height(), $color);
28
            $new->mime = $image->mime;
29
            $image = $new->insert($image, 'top-left', 0, 0);
30
        }
31
32
        return $image;
33
    }
34
}
35