Image   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 44
Duplicated Lines 6.82 %

Importance

Changes 0
Metric Value
dl 3
loc 44
rs 10
c 0
b 0
f 0
wmc 7

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getBackground() 0 3 1
A configure() 3 12 4
A build() 0 9 1
A getFilename() 0 3 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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