InOutControlBuilderTrait   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 0
loc 51
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A take() 0 6 1
A return() 0 6 1
A buildInOutParameters() 0 11 3
1
<?php
2
3
4
namespace hiapi\endpoints\Module\InOutControl;
5
6
use hiapi\endpoints\EndpointConfiguration;
7
use hiapi\endpoints\EndpointConfigurationInterface;
8
use hiapi\endpoints\Exception\EndpointBuildingException;
9
use hiapi\endpoints\Module\InOutControl\VO\Collection;
10
11
/**
12
 * Trait InOutControlBuilderTrait
13
 *
14
 * @author Dmytro Naumenko <[email protected]>
15
 *
16
 * @template TakenType as class-string<BaseCommand>|Collection
17
 * @template ReturnedType as Collection|Collection<object>
18
 */
19
trait InOutControlBuilderTrait
20
{
21
    /**
22
     * @psalm-var TakenType
23
     */
24
    protected $take;
25
26
    /**
27
     * @psalm-var ReturnedType
28
     */
29
    protected $return;
30
31
    /**
32
     * @psalm-param TakenType $classNameOrObject
33
     * @return $this
34
     */
35
    public function take($classNameOrObject): self
36
    {
37
        $this->take = $classNameOrObject;
38
39
        return $this;
40
    }
41
42
    /**
43
     * @psalm-param TakenType $classNameOrObject
44
     * @return $this
45
     */
46
    public function return($classNameOrObject): self
47
    {
48
        $this->return = $classNameOrObject;
49
50
        return $this;
51
    }
52
53
    /**
54
     * @param EndpointConfigurationInterface $config
55
     * @return $this
56
     * @throws EndpointBuildingException
57
     */
58
    protected function buildInOutParameters(EndpointConfigurationInterface $config)
59
    {
60
        if (empty($this->take) || empty($this->return)) {
61
            // TODO: think how to include command name in the exception text
62
            throw EndpointBuildingException::fromBuilder('Both input and output MUST be specified', $this);
63
        }
64
        $config->set('inputType', $this->take);
65
        $config->set('returnType', $this->return);
66
67
        return $this;
68
    }
69
}
70