Completed
Branch BUG/batch-strings-overridden (415991)
by
unknown
09:29 queued 38s
created

CommandHandler   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 25
rs 10
c 0
b 0
f 0
wmc 2
lcom 0
cbo 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A verify() 0 8 2
1
<?php
2
3
namespace EventEspresso\core\services\commands;
4
5
use EventEspresso\core\exceptions\InvalidEntityException;
6
7
/**
8
 * Class CommandHandler
9
 * Description
10
 *
11
 * @package       Event Espresso
12
 * @author        Brent Christensen
13
 * @since         4.9.1
14
 */
15
abstract class CommandHandler implements CommandHandlerInterface
16
{
17
    /**
18
     * Verifies the Command class matches the Handler class
19
     * by simply removing "Handler" from the Command class and then comparing.
20
     * IF the Command Handler has been changed via CommandHandlerManager::addCommandHandler,
21
     * or via the filter in CommandHandlerManager::getCommandHandler(),
22
     * then this method MUST be overridden in the new Command Handler class.
23
     * PLZ NOTE: that it also needs to return itself ($this)
24
     * because the CommandBus utilizes method chaining.
25
     *
26
     * @param CommandInterface $command
27
     * @return CommandHandler
28
     * @throws InvalidEntityException
29
     * @since 4.9.80.p
30
     */
31
    public function verify(CommandInterface $command)
32
    {
33
        $expected = str_replace('CommandHandler', 'Command', get_class($this));
34
        if (! $command instanceof $expected) {
35
            throw new InvalidEntityException($command, $expected);
36
        }
37
        return $this;
38
    }
39
}
40