AbstractTypeField   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
eloc 12
dl 0
loc 38
ccs 17
cts 17
cp 1
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getType() 0 3 1
A setValue() 0 3 1
A getValue() 0 3 1
A setType() 0 7 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Artack\Dsn\Field;
6
7
use Artack\Dsn\Exception\InvalidArgumentException;
8
9
abstract class AbstractTypeField extends AbstractField
10
{
11
    private $type;
12
    private $value;
13
14 40
    public function __construct(string $name, string $value, ?string $type, ?string $comment)
15
    {
16 40
        parent::__construct($name, $comment);
17
18 40
        $this->setValue($value);
19 40
        $this->setType($type);
20 26
    }
21
22 6
    public function getValue(): string
23
    {
24 6
        return $this->value;
25
    }
26
27 40
    public function setValue(string $value): void
28
    {
29 40
        $this->value = $value;
30 40
    }
31
32 20
    public function getType(): string
33
    {
34 20
        return $this->type;
35
    }
36
37 40
    public function setType(?string $type): void
38
    {
39 40
        if (!\in_array($type, $this->getTypes(), true)) {
40 14
            throw new InvalidArgumentException(sprintf('given type "%s" is not one of "%s"', $type, implode(', ', $this->getTypes())));
41
        }
42
43 26
        $this->type = $type;
44 26
    }
45
46
    abstract protected function getTypes(): array;
47
}
48