BufferQueue   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 84
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

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

9 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A enqueue() 0 5 1
A clear() 0 5 1
A current() 0 4 1
A next() 0 4 1
A key() 0 4 1
A valid() 0 4 1
A rewind() 0 4 1
A count() 0 4 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