ValidationMiddleware   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 21
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A deliver() 0 9 2
A __construct() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Werkspot\MessageBus\Bus\DeliveryChain\Middleware\Validation;
6
7
use Werkspot\MessageBus\Bus\DeliveryChain\MiddlewareInterface;
8
use Werkspot\MessageBus\Message\MessageInterface;
9
10
final class ValidationMiddleware implements MiddlewareInterface
11
{
12
    /**
13
     * @var ValidatorInterface
14
     */
15
    private $validator;
16
17 2
    public function __construct(ValidatorInterface $validator)
18
    {
19 2
        $this->validator = $validator;
20 2
    }
21
22 2
    public function deliver(MessageInterface $message, callable $next): void
23
    {
24 2
        $messageViolationListException = $this->validator->validate($message);
25
26 2
        if (count($messageViolationListException) !== 0) {
27 1
            throw $messageViolationListException;
28
        }
29
30 1
        $next($message);
31 1
    }
32
}
33