Completed
Push — master ( 1aea55...3a5ed6 )
by Ivannis Suárez
11:15
created

ValidatorMiddleware   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 12 2
1
<?php
2
3
/**
4
 * This file is part of the Cubiche package.
5
 *
6
 * Copyright (c) Cubiche
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
namespace Cubiche\Core\Bus\Middlewares\Validator;
12
13
use Cubiche\Core\Bus\MessageValidatableInterface;
14
use Cubiche\Core\Bus\Middlewares\MiddlewareInterface;
15
use Cubiche\Core\Validator\Validator;
16
17
/**
18
 * ValidatorMiddleware class.
19
 *
20
 * @author Ivannis Suárez Jerez <[email protected]>
21
 */
22
class ValidatorMiddleware implements MiddlewareInterface
23
{
24
    /**
25
     * {@inheritdoc}
26
     */
27
    public function handle($message, callable $next)
28
    {
29
        if ($message instanceof MessageValidatableInterface) {
30
            $validator = Validator::create();
31
32
            $message->addValidationConstraints($validator);
33
34
            $validator->assert($message);
35
        }
36
37
        $next($message);
38
    }
39
}
40