Completed
Push — master ( c15104...eb04a4 )
by Dmitry
14:35
created

InOutControlBuilderTrait   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

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\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