MessageMapperTrait   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 3
dl 0
loc 43
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A createFrom() 0 4 1
A factory() 0 4 1
A from() 0 8 2
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