ColorBlockMaker::image()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1.0046

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 5
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 9
ccs 5
cts 6
cp 0.8333
crap 1.0046
rs 10
1
<?php
2
3
namespace Limsum\ColorBlock;
4
5
class ColorBlockMaker
6
{
7
8
    /**
9
     * @var string
10
     */
11
    protected string $extension;
12
13
    /**
14
     * @var float
15
     */
16
    protected float $with;
17
18
    /**
19
     * @var float
20
     */
21
    protected float $height;
22
23
    /**
24
     * @var string
25
     */
26
    protected string $color;
27
28
    /**
29
     * @param string $extension
30
     * @param float $with
31
     * @param float $height
32
     * @param string $color
33
     */
34 2
    public function __construct(string $extension, float $with = 100, float $height = 100, string $color = '#808080')
35
    {
36 2
        $this->extension = $extension;
37 2
        $this->with      = $with;
38 2
        $this->height    = $height;
39 2
        $this->color     = $color;
40
    }
41
42 2
    public function image()
43
    {
44 2
        $colorBlockImage =  match ($this->extension) {
45 1
            'png' => ( new ColorBlockPng($this->with, $this->height, $this->color) ),
46
            'jpg', 'jpeg' => ( new ColorBlockJpg($this->with, $this->height, $this->color) ),
47 1
            default => ( new ColorBlockSvg($this->with, $this->height, $this->color) ),
48
        };
49
50 2
        return $colorBlockImage->image();
51
    }
52
}
53