Completed
Push — master ( 6fa888...1dfddd )
by Patrick
02:15
created

ActionField::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 5
rs 10
c 0
b 0
f 0
ccs 3
cts 3
cp 1
cc 1
nc 1
nop 2
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Artack\Dsn\Field;
6
7
use Artack\Dsn\Exception\InvalidArgumentException;
8
9
class ActionField extends AbstractField
10
{
11
    private const ACTIONS = [
12
        'failed',
13
        'delayed',
14
        'delivered',
15
        'relayed',
16
        'expanded',
17
    ];
18
    private $action;
19
20 24
    public function __construct(string $name, string $action)
21
    {
22 24
        parent::__construct($name, null);
23
24 24
        $this->setAction($action);
25 20
    }
26
27 14
    public function getAction(): string
28
    {
29 14
        return $this->action;
30
    }
31
32 24
    public function setAction(string $action): void
33
    {
34 24
        if (!\in_array($action, self::ACTIONS, true)) {
35 4
            throw new InvalidArgumentException(sprintf('given action "%s" is not one of "%s"', $action, implode(', ', self::ACTIONS)));
36
        }
37
38 20
        $this->action = $action;
39 20
    }
40
}
41