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

LogoutMiddleware   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A execute() 0 18 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\LogoutCommand;
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 LogoutMiddleware implements Middleware
17
{
18
    /**
19
     * {@inheritdoc}
20
     */
21
    public function execute($command, callable $next)
22
    {
23
        if (!$subject = $command->storage) {
24
            throw new \LogicException("Require storage before using this AuthenticationMiddleware!");
25
        }
26
27
        if (!$command instanceof LogoutCommand) {
28
            return $next($command);
29
        }
30
31
        /** @var User $subject */
32
        $subject->setLineLastLogin(null);
33
        $subject->setState([User::START_STATE => 1]);
34
35
        $command->message = new TextTemplate();
36
        $command->message->text = 'ออกจากระบบสำเร็จ !';
37
38
        return $next($command);
39
    }
40
}
41