ValidatorMiddleware   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 0
loc 34
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A execute() 0 10 2
1
<?php
2
3
namespace League\Tactician\Bundle\Middleware;
4
5
use League\Tactician\Middleware;
6
use Symfony\Component\Validator\Validator\ValidatorInterface;
7
8
class ValidatorMiddleware implements Middleware
9
{
10
    /**
11
     * @var ValidatorInterface
12
     */
13
    protected $validator;
14
15
    /**
16
     * @param ValidatorInterface $validator
17
     */
18 12
    public function __construct(ValidatorInterface $validator)
19
    {
20 12
        $this->validator = $validator;
21 12
    }
22
23
    /**
24
     * @param object $command
25
     * @param callable $next
26
     *
27
     * @return mixed
28
     *
29
     * @throws InvalidCommandException
30
     */
31 12
    public function execute($command, callable $next)
32
    {
33 12
        $constraintViolations = $this->validator->validate($command);
34
35 12
        if (count($constraintViolations) > 0) {
36 3
            throw InvalidCommandException::onCommand($command, $constraintViolations);
37
        }
38
39 9
        return $next($command);
40
    }
41
}
42
43