MessageMapperTrait::from()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
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