TriggerCommandOnHandle::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 2
1
<?php
2
/**
3
 * This file is part of the Cubiche package.
4
 *
5
 * Copyright (c) Cubiche
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
namespace Cubiche\Core\Cqrs\Tests\Fixtures\Command;
11
12
use Cubiche\Core\Bus\Middlewares\Locking\LockingMiddleware;
13
14
/**
15
 * TriggerCommandOnHandle class.
16
 *
17
 * @author Ivannis Suárez Jerez <[email protected]>
18
 */
19
class TriggerCommandOnHandle
20
{
21
    /**
22
     * @var callable
23
     */
24
    protected $callback;
25
26
    /**
27
     * @var LockingMiddleware
28
     */
29
    protected $middleware;
30
31
    /**
32
     * TriggerCommandOnHandle constructor.
33
     *
34
     * @param LockingMiddleware $middleware
35
     * @param callable          $callback
36
     */
37
    public function __construct(LockingMiddleware $middleware, callable $callback)
38
    {
39
        $this->middleware = $middleware;
40
        $this->callback = $callback;
41
    }
42
43
    /**
44
     * @param LoginUserCommand $command
45
     *
46
     * @return bool
47
     */
48
    public function handle(LoginUserCommand $command)
49
    {
50
        // try to execute the same command before set the value
51
        $this->middleware->handle($command, $this->callback);
52
53
        $command->setPassword(sha1($command->password()));
54
55
        return $command->password();
56
    }
57
}
58