Passed
Push — master ( a105b5...b5df54 )
by Hector Luis
03:56
created

ProxyBus::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 4
rs 10
1
<?php
2
declare(strict_types=1);
3
/**
4
 * Application Use Case Class
5
 * @author Ticaje <[email protected]>
6
 */
7
8
namespace Ticaje\Hexagonal\Application\UseCase\Bus\Decorator;
9
10
use Ticaje\Hexagonal\Application\Signatures\Responder\ResponseInterface;
11
use Ticaje\Hexagonal\Application\Signatures\UseCase\BusFacadeInterface;
12
use Ticaje\Hexagonal\Application\Signatures\UseCase\ImplementorInterface;
13
use Ticaje\Hexagonal\Application\Signatures\UseCase\UseCaseCommandInterface;
14
15
/**
16
 * Class ProxyBus
17
 * @package Ticaje\Hexagonal\Application\UseCase\Bus\Decorator
18
 */
19
class ProxyBus implements BusFacadeInterface
20
{
21
    /** @var ImplementorInterface [] */
22
    private $providers;
23
24
    /**
25
     * Bus constructor.
26
     *
27
     * @param array $providers
28
     */
29
    public function __construct(
30
        array $providers
31
    ) {
32
        $this->providers = $providers;
0 ignored issues
show
Documentation Bug introduced by
It seems like $providers of type array is incompatible with the declared type Ticaje\Hexagonal\Applica...se\ImplementorInterface of property $providers.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
33
    }
34
35
    /**
36
     * @inheritDoc
37
     */
38
    public function execute(UseCaseCommandInterface $command): ResponseInterface
39
    {
40
        if (!isset($this->providers[get_class($command)])) {
41
            throw new \InvalidArgumentException('There are no commands assigned to this Handler');
42
        }
43
        $provider = $this->providers[get_class($command)];
44
        $bus = $provider->provide([]);
45
        if (!$bus) {
46
            throw new \Exception('Bus not found');
47
        }
48
49
        return $bus->handle($command);
50
    }
51
}
52