Image::getBackground()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 1
nop 0
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace EaselDrawing\Elements;
4
5
use EaselDrawing\AbstractElement;
6
use EaselDrawing\Color;
7
8
class Image extends AbstractElement
9
{
10
    /** @var string */
11
    private $filename;
12
13
    /** @var Color|null */
14
    private $background;
15
16
    public function __construct($x, $y, $width, $height, string $filename, Color $background = null)
17
    {
18
        parent::__construct($x, $y, $width, $height);
19
        $this->filename = $filename;
20
        $this->background = $background;
21
    }
22
23
    public function getFilename(): string
24
    {
25
        return $this->filename;
26
    }
27
28
    public function hasBackground(): bool
29
    {
30
        return (null !== $this->background);
31
    }
32
33
    public function getBackground(): Color
34
    {
35
        if (! $this->hasBackground()) {
36
            throw new \RuntimeException('The Image does not have a background color set');
37
        }
38
        return $this->background;
39
    }
40
}
41