Completed
Push — master ( 4a65be...8e0add )
by Olivier
03:17
created

SimpleMessageHandlerProvider   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 1
dl 0
loc 30
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A __invoke() 0 11 2
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 simple implementation of {@link MessageHandlerProvider}.
16
 */
17
class SimpleMessageHandlerProvider implements MessageHandlerProvider
18
{
19
	/**
20
	 * @var array
21
	 */
22
	private $handlers;
23
24
	/**
25
	 * @param MessageHandler[]|callable[] $handlers
26
	 */
27
	public function __construct(array $handlers)
28
	{
29
		$this->handlers = $handlers;
30
	}
31
32
	/**
33
	 * @inheritdoc
34
	 */
35
	public function __invoke(Message $message)
36
	{
37
		$class = get_class($message);
38
39
		if (empty($this->handlers[$class]))
40
		{
41
			throw new NoHandlerForMessage($message);
42
		}
43
44
		return $this->handlers[$class];
45
	}
46
}
47