MemoryPullCommandQueue::publish()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
declare(strict_types=1);
3
4
/**
5
 * GpsLab component.
6
 *
7
 * @author    Peter Gribanov <[email protected]>
8
 * @copyright Copyright (c) 2011, Peter Gribanov
9
 * @license   http://opensource.org/licenses/MIT
10
 */
11
12
namespace GpsLab\Component\Command\Queue\Pull;
13
14
use GpsLab\Component\Command\Command;
15
16
class MemoryPullCommandQueue implements PullCommandQueue
17
{
18
    /**
19
     * @var Command[]
20
     */
21
    private $commands = [];
22
23
    /**
24
     * Publish command to queue.
25
     *
26
     * @param Command $command
27
     *
28
     * @return bool
29
     */
30 1
    public function publish(Command $command): bool
31
    {
32 1
        $this->commands[] = $command;
33
34 1
        return true;
35
    }
36
37
    /**
38
     * Pop command from queue. Return NULL if queue is empty.
39
     *
40
     * @return Command|null
41
     */
42 1
    public function pull(): ?Command
43
    {
44 1
        return array_shift($this->commands);
45
    }
46
}
47