Completed
Push — master ( f371bb...9f93eb )
by Julián
02:32
created

CommandExtractor   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 7
c 1
b 0
f 0
dl 0
loc 22
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A extract() 0 11 3
1
<?php
2
3
/*
4
 * cqrs-tactician (https://github.com/phpgears/cqrs-tactician).
5
 * CQRS implementation with League Tactician.
6
 *
7
 * @license MIT
8
 * @link https://github.com/phpgears/cqrs-tactician
9
 * @author Julián Gutiérrez <[email protected]>
10
 */
11
12
declare(strict_types=1);
13
14
namespace Gears\CQRS\Tactician;
15
16
use Gears\CQRS\Command;
17
use Gears\CQRS\Exception\InvalidCommandException;
18
use League\Tactician\Handler\CommandNameExtractor\CommandNameExtractor;
19
20
final class CommandExtractor implements CommandNameExtractor
21
{
22
    /**
23
     * Extract the name from a command.
24
     *
25
     * @param mixed $command
26
     *
27
     * @throws InvalidCommandException
28
     *
29
     * @return string
30
     */
31
    public function extract($command)
32
    {
33
        if (!$command instanceof Command) {
34
            throw new InvalidCommandException(\sprintf(
35
                'Command must implement "%s" interface, "%s" given',
36
                Command::class,
37
                \is_object($command) ? \get_class($command) : \gettype($command)
38
            ));
39
        }
40
41
        return $command->getCommandType();
42
    }
43
}
44