Completed
Push — master ( 3c1d03...7e0a80 )
by Dmitry
14:29
created

ValidateCommandMiddleware   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 1
dl 0
loc 18
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A execute() 0 8 2
1
<?php declare(strict_types=1);
2
3
namespace hiapi\middlewares;
4
5
use hiapi\commands\BaseCommand;
6
use hiapi\exceptions\domain\ValidationException;
7
8
/**
9
 * Class ValidateCommandMiddleware
10
 *
11
 * @author Dmytro Naumenko <[email protected]>
12
 */
13
class ValidateCommandMiddleware
14
{
15
    /**
16
     * @param object|BaseCommand $command
17
     * @param callable $next
18
     *
19
     * @return mixed
20
     * @throws ValidationException when data is not valid
21
     */
22
    public function execute($command, callable $next)
23
    {
24
        if (!$command->validate()) {
25
            throw new ValidationException(implode(', ', $command->getFirstErrors()));
26
        }
27
28
        return $next($command);
29
    }
30
}
31