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

ActionField   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
eloc 14
dl 0
loc 30
rs 10
c 0
b 0
f 0
ccs 10
cts 10
cp 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setAction() 0 7 2
A getAction() 0 3 1
A __construct() 0 5 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