HandlerProviderWithChain::getHandlerForMessage()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 5
nc 3
nop 1
dl 0
loc 11
rs 10
c 1
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of the ICanBoogie package.
5
 *
6
 * (c) Olivier Laviale <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace ICanBoogie\MessageBus;
13
14
/**
15
 * A handler provider backed with a chain of providers.
16
 */
17
final class HandlerProviderWithChain implements HandlerProvider
18
{
19
    /**
20
     * @param iterable<HandlerProvider> $providers
21
     */
22
    public function __construct(
23
        private iterable $providers
24
    ) {
25
    }
26
27
    public function getHandlerForMessage(object $message): ?callable
28
    {
29
        foreach ($this->providers as $provider) {
30
            $handler = $provider->getHandlerForMessage($message);
31
32
            if ($handler) {
33
                return $handler;
34
            }
35
        }
36
37
        return null;
38
    }
39
}
40