Completed
Push — master ( c15104...eb04a4 )
by Dmitry
14:35
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
c 0
b 0
f 0
rs 9.9
cc 3
nc 2
nop 1
1
<?php
2
3
4
namespace hiapi\endpoints\Module\InOutControl;
5
6
use hiapi\endpoints\EndpointConfig;
7
use hiapi\endpoints\Exception\EndpointBuildingException;
8
9
/**
10
 * Trait InOutControlBuilderTrait
11
 *
12
 * @author Dmytro Naumenko <[email protected]>
13
 */
14
trait InOutControlBuilderTrait
15
{
16
    /**
17
     * @psalm-var class-string
18
     */
19
    protected $take;
20
21
    /**
22
     * @psalm-var class-string
23
     */
24
    protected $return;
25
26
    public function take(string $className)
27
    {
28
        $this->take = $className;
29
30
        return $this;
31
    }
32
33
    public function return(string $className)
34
    {
35
        $this->return = $className;
36
37
        return $this;
38
    }
39
40
    /**
41
     * @param EndpointConfig $config
42
     * @return $this
43
     * @throws EndpointBuildingException
44
     */
45
    protected function buildInOutparameters(EndpointConfig $config)
46
    {
47
        if (empty($this->take) || empty($this->return)) {
48
            // TODO: think how to include command name in the exception text
49
            throw EndpointBuildingException::fromBuilder('Both input and output MUST be specified', $this);
50
        }
51
        $config->set('take', $this->take);
52
        $config->set('return', $this->return);
53
54
        return $this;
55
    }
56
}
57