Code Duplication    Length = 25-26 lines in 2 locations

src/Mocky/Auth/Middleware/ClearActiveMiddleware.php 1 location

@@ 16-41 (lines=26) @@
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
        /** @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

src/Mocky/Auth/Middleware/LogoutMiddleware.php 1 location

@@ 16-40 (lines=25) @@
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);
34
35
        $command->message = new TextTemplate();
36
        $command->message->text = 'ออกจากระบบสำเร็จ !';
37
38
        return $next($command);
39
    }
40
}
41