MessageListener::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 7
cts 7
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 3
crap 1
1
<?php
2
3
/*
4
 * Copyright (c) 2011-2015, Celestino Diaz <[email protected]>
5
 *
6
 * Permission is hereby granted, free of charge, to any person obtaining a copy
7
 * of this software and associated documentation files (the "Software"), to deal
8
 * in the Software without restriction, including without limitation the rights
9
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
 * copies of the Software, and to permit persons to whom the Software is
11
 * furnished to do so, subject to the following conditions:
12
 *
13
 * The above copyright notice and this permission notice shall be included in
14
 * all copies or substantial portions of the Software.
15
 *
16
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
 * THE SOFTWARE.
23
 */
24
25
namespace Brickoo\Component\Messaging;
26
27
use Brickoo\Component\Common\Assert;
28
29
/**
30
 * MessageListener
31
 *
32
 * Implements a generic message listener.
33
 * @author Celestino Diaz <[email protected]>
34
 */
35
class MessageListener implements Listener {
36
37
    /** @var string */
38
    private $messageName;
39
40
    /** @var integer */
41
    private $priority;
42
43
    /** @var callable */
44
    private $callback;
45
46
    /**
47
     * @param string $messageName
48
     * @param integer $priority
49
     * @param callable $callback
50
     */
51 2
    public function __construct($messageName, $priority, callable $callback) {
52 2
        Assert::isString($messageName);
53 2
        Assert::isInteger($priority);
54
55 1
        $this->messageName = $messageName;
56 1
        $this->priority = $priority;
57 1
        $this->callback = $callback;
58 1
    }
59
60
    /** {@inheritDoc} */
61 1
    public function getMessageName() {
62 1
        return $this->messageName;
63
    }
64
65
    /** {@inheritDoc} */
66 1
    public function getPriority() {
67 1
        return $this->priority;
68
    }
69
70
    /** {@inheritDoc} */
71 1
    public function handleMessage(Message $message, MessageDispatcher $dispatcher) {
72 1
        call_user_func_array($this->callback, [$message, $dispatcher]);
73 1
    }
74
75
}
76