AddActionTypeTrait   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
eloc 15
c 0
b 0
f 0
dl 0
loc 35
ccs 16
cts 16
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A addActionType() 0 21 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace kalanis\Pohoda\Common;
6
7
use kalanis\Pohoda\Type;
8
use kalanis\PohodaException;
9
10
/**
11
 * @property object{
12
 *     actionType?: Type\ActionType,
13
 * } $data
14
 */
15
trait AddActionTypeTrait
16
{
17
    /**
18
     * Add action type.
19
     *
20
     * @param string      $type
21
     * @param array<string, string|int|float|bool|array<string, string|int|float|bool>>  $filter
22
     * @param string|null $agenda
23
     *
24
     * @throws PohodaException
25
     * @throws \ReflectionException
26
     *
27
     * @return $this
28
     */
29 8
    public function addActionType(string $type, array $filter = [], ?string $agenda = null): self
30
    {
31 8
        if (!empty($this->data->actionType)) {
32 1
            throw new PohodaException('Duplicate action type.');
33
        }
34
35 8
        $actionTypeDto = new Type\Dtos\ActionTypeDto();
36 8
        $actionTypeDto->type = $type;
37 8
        $actionTypeDto->filter = $filter;
38 8
        $actionTypeDto->agenda = $agenda;
39
40 8
        $actionType = new Type\ActionType(
41 8
            $this->dependenciesFactory,
42 8
        );
43 8
        $actionType
44 8
            ->setDirectionalVariable($this->useOneDirectionalVariables)
45 8
            ->setResolveOptions($this->resolveOptions)
46 8
            ->setData($actionTypeDto);
47 8
        $this->data->actionType = $actionType;
48
49 8
        return $this;
50
    }
51
}
52