Message::getMetadata()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
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\ContainerInterface;
19
20
final class Message implements MessageInterface
21
{
22
    /**
23
     * @var string
24
     */
25
    protected $body;
26
27
    /**
28
     * @var ContainerInterface
29
     */
30
    protected $metadata;
31
32
    /**
33
     * @var callable
34
     */
35
    protected $validator;
36
37
    /**
38
     * @param string             $body
39
     * @param ContainerInterface $metadata
40
     * @param callable           $validator
41
     */
42 23
    public function __construct($body, ContainerInterface $metadata, callable $validator)
43
    {
44 23
        $this->body = (string) $body;
45 23
        $this->metadata = $metadata;
46 23
        $this->validator = $validator;
47 23
    }
48
49
    /**
50
     * @return string
51
     */
52 7
    public function getBody()
53
    {
54 7
        return $this->body;
55
    }
56
57
    /**
58
     * @return ContainerInterface
59
     */
60 7
    public function getMetadata()
61
    {
62 7
        return $this->metadata;
63
    }
64
65
    /**
66
     * @return bool
67
     */
68 11
    public function isValid()
69
    {
70 11
        return (boolean) call_user_func($this->validator, $this);
71
    }
72
}
73