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

QueryExtractor::extract()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 11
rs 10
cc 3
nc 2
nop 1
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\Exception\InvalidQueryException;
17
use Gears\CQRS\Query;
18
use League\Tactician\Handler\CommandNameExtractor\CommandNameExtractor;
19
20
final class QueryExtractor implements CommandNameExtractor
21
{
22
    /**
23
     * Extract the name from a query.
24
     *
25
     * @param mixed $query
26
     *
27
     * @throws InvalidQueryException
28
     *
29
     * @return string
30
     */
31
    public function extract($query)
32
    {
33
        if (!$query instanceof Query) {
34
            throw new InvalidQueryException(\sprintf(
35
                'Query must implement "%s" interface, "%s" given',
36
                Query::class,
37
                \is_object($query) ? \get_class($query) : \gettype($query)
38
            ));
39
        }
40
41
        return $query->getQueryType();
42
    }
43
}
44