Completed
Push — master ( d1f44d...2f7083 )
by Kamil
02:59
created

Queue   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
c 0
b 0
f 0
lcom 1
cbo 1
dl 0
loc 55
ccs 0
cts 23
cp 0
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A isEmpty() 0 4 1
A enqueue() 0 6 1
A dequeue() 0 4 1
A unshift() 0 5 1
1
<?php
2
3
namespace Dazzle\MySQL\Support\Queue;
4
5
use Dazzle\Event\BaseEventEmitter;
6
use Dazzle\MySQL\Protocol\CommandInterface;
7
use SplQueue;
8
9
class Queue extends BaseEventEmitter implements QueueInterface
10
{
11
    /**
12
     * @var SplQueue
13
     */
14
    public $queue;
15
16
    /**
17
     *
18
     */
19
    public function __construct()
20
    {
21
        $this->queue = new SplQueue();
22
    }
23
24
    /**
25
     * @override
26
     * @inheritDoc
27
     */
28
    public function isEmpty()
29
    {
30
        return $this->queue->isEmpty();
31
    }
32
33
    /**
34
     * @override
35
     * @inheritDoc
36
     */
37
    public function enqueue(CommandInterface $command)
38
    {
39
        $this->queue->enqueue($command);
40
        $this->emit('new');
41
        return $command;
42
    }
43
44
    /**
45
     * @override
46
     * @inheritDoc
47
     */
48
    public function dequeue()
49
    {
50
        return $this->queue->dequeue();
51
    }
52
53
    /**
54
     * Unshift command.
55
     *
56
     * @return CommandInterface
57
     */
58
    public function unshift(CommandInterface $command)
59
    {
60
        $this->queue->unshift($command);
61
        return $command;
62
    }
63
}
64