Align::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace EaselDrawing;
4
5
class Align
6
{
7
    const LEFT = 'LEFT';
8
    const CENTER = 'CENTER';
9
    const RIGHT = 'RIGHT';
10
11
    private $value;
12
13
    public function __construct(string $value)
14
    {
15
        $this->setValue($value);
16
    }
17
18 View Code Duplication
    public function setValue(string $value)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
19
    {
20
        if (! in_array($value, [static::LEFT, static::CENTER, static::RIGHT])) {
21
            throw new \InvalidArgumentException('Align value is not valid');
22
        }
23
        $this->value = $value;
24
    }
25
26
    public function getValue()
27
    {
28
        return $this->value;
29
    }
30
31 View Code Duplication
    public static function newFromString(string $value)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
32
    {
33
        $value = strtoupper($value);
34
        if (! in_array($value, [static::LEFT, static::CENTER, static::RIGHT])) {
35
            $value = static::LEFT;
36
        }
37
        return new Align($value);
38
    }
39
}
40