ProtectOrder::dispatch()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 16
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 8
c 0
b 0
f 0
dl 0
loc 16
rs 10
cc 3
nc 2
nop 1
1
<?php
2
declare(strict_types=1);
3
4
namespace OniBus\Buses;
5
6
use OniBus\Chain;
7
use OniBus\ChainTrait;
8
use OniBus\Message;
9
10
class ProtectOrder implements Chain
11
{
12
    use ChainTrait;
13
14
    /**
15
     * @var array
16
     */
17
    protected $queue;
18
19
    /**
20
     * @var bool
21
     */
22
    protected $isDispatching = false;
23
24
    public function dispatch(Message $message)
25
    {
26
        $this->queue[] = $message;
27
        $lastResult = null;
28
29
        if (!$this->isDispatching) {
30
            $this->isDispatching = true;
31
32
            while ($message = array_shift($this->queue)) {
33
                $lastResult = $this->next($message);
34
            }
35
36
            $this->isDispatching = false;
37
        }
38
39
        return $lastResult;
40
    }
41
}
42