Image   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 31
rs 10
c 0
b 0
f 0
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getBackground() 0 6 2
A getFilename() 0 3 1
A hasBackground() 0 3 1
A __construct() 0 5 1
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