AddActionTypeTrait::addActionType()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 21
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 16
CRAP Score 2

Importance

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