Completed
Pull Request — master (#292)
by Pascal
04:22 queued 03:11
created

Background   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 4
dl 0
loc 24
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A run() 0 16 3
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 3
    public function run(Image $image)
19
    {
20 3
        if (is_null($this->bg)) {
21 3
            return $image;
22
        }
23
24 3
        $color = (new Color($this->bg))->formatted();
25
26 3
        if ($color) {
27 3
            $new = $image->getDriver()->newImage($image->width(), $image->height(), $color);
28 3
            $new->mime = $image->mime;
29 3
            $image = $new->insert($image, 'top-left', 0, 0);
30
        }
31
32 3
        return $image;
33
    }
34
}
35