CommandHandler   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 4
dl 0
loc 29
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A handle() 0 9 1
A assertCommandJob() 0 6 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Lamoda\TacticianQueue\Handler;
6
7
use Lamoda\QueueBundle\Handler\HandlerInterface;
8
use Lamoda\QueueBundle\QueueInterface;
9
use Lamoda\TacticianQueue\Exception\CanNotHandleJobException;
10
use Lamoda\TacticianQueue\Job\CommandJob;
11
use Lamoda\TacticianQueue\Middleware\Command\ReceivedCommand;
12
use League\Tactician\CommandBus;
13
14
final class CommandHandler implements HandlerInterface
15
{
16
    /**
17
     * @var CommandBus
18
     */
19
    private $commandBus;
20
21 2
    public function __construct(CommandBus $commandBus)
22
    {
23 2
        $this->commandBus = $commandBus;
24 2
    }
25
26 2
    public function handle(QueueInterface $job)
27
    {
28
        /* @var CommandJob $job */
29 2
        $this->assertCommandJob($job);
30
31 1
        $receivedCommand = new ReceivedCommand($job->getCommand());
32
33 1
        $this->commandBus->handle($receivedCommand);
34 1
    }
35
36 2
    private function assertCommandJob(QueueInterface $job): void
37
    {
38 2
        if (!$job instanceof CommandJob) {
39 1
            throw CanNotHandleJobException::becauseJobShouldInstanceOf(CommandJob::class);
40
        }
41 1
    }
42
}
43