AbstractTypeField::setType()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 7
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 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