BufferQueue::key()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
/*
3
 * This file is part of the Twig Bufferized Template package, an RunOpenCode project.
4
 *
5
 * (c) 2017 RunOpenCode
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
namespace RunOpenCode\Twig\BufferizedTemplate\Buffer;
11
12
/**
13
 * Class BufferQueue
14
 *
15
 * Buffer queue contains list of buffered template portions sorted by execution priority.
16
 *
17
 * @package RunOpenCode\Twig\BufferizedTemplate\Buffer
18
 */
19
final class BufferQueue implements \Countable, \Iterator
20
{
21
    /**
22
     * @var \SplPriorityQueue
23
     */
24
    private $queue;
25
26 5
    public function __construct()
27
    {
28 5
        $this->queue = new \SplPriorityQueue();
29 5
    }
30
31
    /**
32
     * Add template buffer to queue.
33
     *
34
     * @param TemplateBuffer $buffer
35
     *
36
     * @return BufferQueue $this
37
     */
38 5
    public function enqueue(TemplateBuffer $buffer)
39
    {
40 5
        $this->queue->insert($buffer, $buffer->getPriority());
41 5
        return $this;
42
    }
43
44
    /**
45
     * Clears queue
46
     *
47
     * @return BufferQueue $this
48
     */
49 1
    public function clear()
50
    {
51 1
        $this->queue = new \SplPriorityQueue();
52 1
        return $this;
53
    }
54
55
    /**
56
     * {@inheritdoc}
57
     */
58 5
    public function current()
59
    {
60 5
        return $this->queue->current();
61
    }
62
63
    /**
64
     * {@inheritdoc}
65
     */
66 5
    public function next()
67
    {
68 5
        $this->queue->next();
69 5
    }
70
71
    /**
72
     * {@inheritdoc}
73
     */
74 1
    public function key()
75
    {
76 1
        return $this->queue->key();
77
    }
78
79
    /**
80
     * {@inheritdoc}
81
     */
82 5
    public function valid()
83
    {
84 5
        return $this->queue->valid();
85
    }
86
87
    /**
88
     * {@inheritdoc}
89
     */
90 5
    public function rewind()
91
    {
92 5
        $this->queue->rewind();
93 5
    }
94
95
    /**
96
     * {@inheritdoc}
97
     */
98 1
    public function count()
99
    {
100 1
        return $this->queue->count();
101
    }
102
}
103