Completed
Push — master ( eb04a4...cf4b83 )
by Dmitry
11:42
created

InOutControlBuilderTrait::buildInOutParameters()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.9
c 0
b 0
f 0
cc 3
nc 2
nop 1
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
10
/**
11
 * Trait InOutControlBuilderTrait
12
 *
13
 * @author Dmytro Naumenko <[email protected]>
14
 */
15
trait InOutControlBuilderTrait
16
{
17
    /**
18
     * @psalm-var class-string
19
     */
20
    protected $take;
21
22
    /**
23
     * @psalm-var class-string
24
     */
25
    protected $return;
26
27
    public function take(string $className)
28
    {
29
        $this->take = $className;
30
31
        return $this;
32
    }
33
34
    public function return(string $className)
35
    {
36
        $this->return = $className;
37
38
        return $this;
39
    }
40
41
    /**
42
     * @param EndpointConfigurationInterface $config
43
     * @return $this
44
     * @throws EndpointBuildingException
45
     */
46
    protected function buildInOutParameters(EndpointConfigurationInterface $config)
47
    {
48
        if (empty($this->take) || empty($this->return)) {
49
            // TODO: think how to include command name in the exception text
50
            throw EndpointBuildingException::fromBuilder('Both input and output MUST be specified', $this);
51
        }
52
        $config->set('take', $this->take);
53
        $config->set('return', $this->return);
54
55
        return $this;
56
    }
57
}
58