Passed
Push — master ( 01baf6...9ed857 )
by Vitor de
04:10
created

CommandBus::receive()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 13
ccs 9
cts 9
cp 1
rs 9.4285
cc 1
eloc 8
nc 1
nop 1
crap 1
1
<?php
2
3
namespace GFG\Hek;
4
5
class CommandBus
6
{
7
    /**
8
     * @var Manager
9
     */
10
    private $manager;
11
12
    /**
13
     * @param Manager $manager
14
     */
15 3
    public function __construct(Manager $manager)
16
    {
17 3
        $this->manager = $manager;
18 3
    }
19
20
    /**
21
     * @return Manager
22
     */
23 3
    public function getManager()
24
    {
25 3
        return $this->manager;
26
    }
27
28
    /**
29
     * @param array $dtoData
30
     * @return mixed
31
     */
32 1
    public function receive(array $dtoData)
33
    {
34 1
        $context = $this->getManager()->getContextManager()->rebuild(
35 1
            $dtoData,
36 1
            $this->getManager()->getContextManager()->getHydrator()
37 1
        );
38
39 1
        $explode = explode('.', $context->getName());
40 1
        $action  = end($explode);
41 1
        $service = $this->getManager()->getServiceFactory()->build($context);
42
43 1
        return $service->$action($context);
44
    }
45
46
    /**
47
     * @param Interfaces\Context $context
48
     * @return mixed
49
     */
50 1
    public function send(Interfaces\Context $context)
51
    {
52 1
        return $this->getManager()->getApiClient()->execute($context);
53
    }
54
}
55