Completed
Push — master ( a40390...c25130 )
by
11s
created

ClearActiveMiddleware   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
dl 0
loc 24
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A execute() 0 19 3
1
<?php
2
3
namespace LineMob\Core\Mocky\Auth\Middleware;
4
5
use League\Tactician\Middleware;
6
use LineMob\Core\Input;
7
use LineMob\Core\Mocky\Auth\Command\ClearActiveCommand;
8
use LineMob\Core\Mocky\Doctrine\Model\User;
9
use LineMob\Core\Template\TextTemplate;
10
use Symfony\Component\Workflow\DefinitionBuilder;
11
use Symfony\Component\Workflow\MarkingStore\MultipleStateMarkingStore;
12
use Symfony\Component\Workflow\Registry;
13
use Symfony\Component\Workflow\Transition;
14
use Symfony\Component\Workflow\Workflow;
15
16
class ClearActiveMiddleware implements Middleware
17
{
18
    /**
19
     * {@inheritdoc}
20
     */
21
    public function execute($command, callable $next)
22
    {
23
        if (!$command instanceof ClearActiveCommand) {
24
            return $next($command);
25
        }
26
27
        if (!$subject = $command->storage) {
28
            throw new \LogicException("Require storage before using this middleware!");
29
        }
30
31
        $command->message = new TextTemplate();
32
        $command->message->text = sprintf('Cancel a command %s', $command->storage->getLineActiveCmd());
33
34
        /** @var User $subject */
35
        $subject->setLineActiveCmd(null);
36
        $subject->setLineCommandData([]);
37
        $subject->setState([User::START_STATE => 1]);
38
39
        return $next($command);
40
    }
41
}
42