Passed
Pull Request — master (#18)
by
unknown
02:29
created

ClearActiveMiddleware::execute()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 19
Code Lines 10

Duplication

Lines 19
Ratio 100 %

Importance

Changes 0
Metric Value
dl 19
loc 19
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 10
nc 2
nop 2
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 View Code Duplication
class ClearActiveMiddleware implements Middleware
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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
        /** @var User $subject */
32
        $subject->setLineActiveCmd(null);
33
        $subject->setLineCommandData([]);
34
        $subject->setState(User::START_STATE);
35
36
        $command->message = new TextTemplate();
37
        $command->message->text = 'ยกเลิกคำสั่งเรียบร้อย';
38
39
        return $next($command);
40
    }
41
}
42