Image::build()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 7
nc 1
nop 0
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
1
<?php
2
3
namespace EaselDrawing\Templates\Builders;
4
5
use EaselDrawing\Color;
6
use EaselDrawing\ElementInterface;
7
use EaselDrawing\Elements\Image as Element;
8
use EaselDrawing\Templates\Template;
9
use EaselDrawing\Templates\Utilities;
10
11
class Image extends AbstractBuilder
12
{
13
    /** @var string */
14
    private $filename = '';
15
    /** @var Color|null */
16
    private $background;
17
18
    public function getFilename(): string
19
    {
20
        return $this->filename;
21
    }
22
23
    /**
24
     * @return Color|null
25
     */
26
    public function getBackground()
27
    {
28
        return $this->background;
29
    }
30
31
    public function configure(array $data, Template $template)
32
    {
33
        parent::configure($data, $template);
34
35
        // filename
36 View Code Duplication
        if (! isset($data['file']) || ! is_string($data['file'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
37
            $data['file'] = '';
38
        }
39
        $this->filename = $template->getPathResolver()->obtainPath($data['file']);
40
        // background (remember that background is optional)
41
        if (isset($data['background'])) {
42
            $this->background = Utilities::interpretColor($data['background'], $template->getBackground());
43
        }
44
    }
45
46
    public function build(): ElementInterface
47
    {
48
        return new Element(
49
            $this->getX(),
50
            $this->getY(),
51
            $this->getWidth(),
52
            $this->getHeight(),
53
            $this->getFilename(),
54
            $this->getBackground()
55
        );
56
    }
57
}
58