Completed
Push — master ( f61059...fbff81 )
by Peter
05:40
created

ExecutingCommandQueue   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 34
c 0
b 0
f 0
wmc 3
lcom 1
cbo 0
ccs 8
cts 8
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A publish() 0 9 2
A subscribe() 0 4 1
1
<?php
2
3
/**
4
 * GpsLab component.
5
 *
6
 * @author    Peter Gribanov <[email protected]>
7
 * @copyright Copyright (c) 2011, Peter Gribanov
8
 * @license   http://opensource.org/licenses/MIT
9
 */
10
11
namespace GpsLab\Component\Command\Queue\PubSub;
12
13
use GpsLab\Component\Command\Command;
14
15
class ExecutingCommandQueue implements CommandQueue
16
{
17
    /**
18
     * @var callable|null
19
     */
20
    private $callback;
21
22
    /**
23
     * Publish command to queue.
24
     *
25
     * @param Command $command
26
     *
27
     * @return bool
28
     */
29 1
    public function publish(Command $command)
30
    {
31
        // absence of a subscriber is not a error
32 1
        if (is_callable($this->callback)) {
33 1
            call_user_func($this->callback, $command);
34 1
        }
35
36 1
        return true;
37
    }
38
39
    /**
40
     * Subscribe on command queue.
41
     *
42
     * @param callable $callback
43
     */
44 1
    public function subscribe(callable $callback)
45
    {
46 1
        $this->callback = $callback;
47 1
    }
48
}
49