Completed
Push — master ( 67a91e...657487 )
by Peter
06:52
created

ValidatorMiddlewareHandler   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A handle() 0 10 2
1
<?php
2
3
/**
4
 * GpsLab component.
5
 *
6
 * @author    Peter Gribanov <[email protected]>
7
 * @copyright Copyright (c) 2011, Peter Gribanov
8
 * @license   http://opensource.org/licenses/MIT
9
 */
10
11
namespace GpsLab\Component\Middleware\Handler;
12
13
use GpsLab\Component\Middleware\Handler\Exception\InvalidMessageException;
14
use Symfony\Component\Validator\Validator\ValidatorInterface;
15
16
class ValidatorMiddlewareHandler implements MiddlewareHandler
17
{
18
    /**
19
     * @var ValidatorInterface
20
     */
21
    protected $validator;
22
23
    /**
24
     * @param ValidatorInterface $validator
25
     */
26
    public function __construct(ValidatorInterface $validator)
27
    {
28
        $this->validator = $validator;
29
    }
30
31
    /**
32
     * @param mixed    $message
33
     * @param callable $next
34
     *
35
     * @return mixed
36
     */
37
    public function handle($message, callable $next)
38
    {
39
        $violations = $this->validator->validate($message);
40
41
        if (count($violations)) {
42
            throw new InvalidMessageException($violations);
43
        }
44
45
        return $next($message);
46
    }
47
}
48