MessageFactory   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 34
ccs 7
cts 7
cp 1
rs 10
c 0
b 0
f 0
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A createMessage() 0 3 1
A getMetadata() 0 5 2
A getValidator() 0 4 2
1
<?php
2
3
/**
4
 * This file is part of graze/queue.
5
 *
6
 * Copyright (c) 2015 Nature Delivered Ltd. <https://www.graze.com>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 *
11
 * @license https://github.com/graze/queue/blob/master/LICENSE MIT
12
 *
13
 * @link    https://github.com/graze/queue
14
 */
15
16
namespace Graze\Queue\Message;
17
18
use Graze\DataStructure\Container\ImmutableContainer;
19
20
final class MessageFactory implements MessageFactoryInterface
21
{
22
    /**
23
     * @param string $body
24
     * @param array  $options
25
     *
26
     * @return Message
27
     */
28 17
    public function createMessage($body, array $options = [])
29
    {
30 17
        return new Message($body, $this->getMetadata($options), $this->getValidator($options));
31
    }
32
33
    /**
34
     * @param array $options
35
     *
36
     * @return ImmutableContainer
37
     */
38 17
    protected function getMetadata(array $options)
39
    {
40 17
        $metadata = isset($options['metadata']) ? $options['metadata'] : [];
41
42 17
        return new ImmutableContainer($metadata);
43
    }
44
45
    /**
46
     * @param array $options
47
     *
48
     * @return \Closure
49
     */
50
    protected function getValidator(array $options)
51
    {
52 17
        return isset($options['validator']) ? $options['validator'] : function () {
53 3
            return true;
54 17
        };
55
    }
56
}
57