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

ValidatorMiddleware::handle()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 12
rs 9.4285
cc 2
eloc 6
nc 2
nop 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