Completed
Push — master ( 3ea98f...31081b )
by Iqbal
02:31
created

MessageMapperTrait::normalizeData()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 20
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 20
rs 8.8571
cc 5
eloc 10
nc 5
nop 1
1
<?php
2
/*
3
 * This file is part of the Borobudur-Bus package.
4
 *
5
 * (c) Hexacodelabs <http://hexacodelabs.com>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Borobudur\Bus\Message;
12
13
use Borobudur\Bus\Exception\InvalidArgumentException;
14
15
/**
16
 * @author      Iqbal Maulana <[email protected]>
17
 * @created     10/12/15
18
 */
19
trait MessageMapperTrait
20
{
21
    /**
22
     * Factory create object from message.
23
     *
24
     * @param mixed $message
25
     *
26
     * @return static
27
     */
28
    public static function createFrom($message)
29
    {
30
        return MessageMapperBuilder::create(get_called_class(), $message);
31
    }
32
33
    /**
34
     * Factory create
35
     *
36
     * @param string $method
37
     * @param mixed $message
38
     *
39
     * @return static
40
     */
41
    public static function factory($method, $message)
42
    {
43
        return MessageMapperBuilder::call(get_called_class(), $method, $message);
44
    }
45
46
    /**
47
     * Map message to object.
48
     *
49
     * @param mixed $message
50
     *
51
     * @return MessageMapperDispatcher
52
     */
53
    public function from($message)
54
    {
55
        if (!is_object($message)) {
56
            throw new InvalidArgumentException(sprintf('Message should be object, "%s" given.', gettype($message)));
57
        }
58
59
        return new MessageMapperDispatcher($message, $this);
60
    }
61
}
62