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

ClearActiveMiddleware   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 100 %

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A execute() 19 19 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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