Completed
Push — develop ( 37b578...155f55 )
by jake
01:36
created

Queue::clear()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 6
ccs 2
cts 2
cp 1
rs 9.4285
cc 2
eloc 3
nc 2
nop 0
crap 2
1
<?php
2
/**
3
 * Purple - Run tasks on collections
4
 *
5
 * PHP version 5
6
 *
7
 * Copyright (C) 2016 Jake Johns
8
 *
9
 * This software may be modified and distributed under the terms
10
 * of the MIT license.  See the LICENSE file for details.
11
 *
12
 * @category  Queue
13
 * @package   Jnjxp\Purple
14
 * @author    Jake Johns <[email protected]>
15
 * @copyright 2016 Jake Johns
16
 * @license   http://jnj.mit-license.org/2016 MIT License
17
 * @link      https://github.com/jnjxp/jnjxp.purple
18
 */
19
20
namespace Jnjxp\Purple;
21
22
use IteratorAggregate;
23
24
/**
25
 * Queue
26
 *
27
 * @category Queue
28
 * @package  Jnjxp\Purple
29
 * @author   Jake Johns <[email protected]>
30
 * @license  http://jnj.mit-license.org/ MIT License
31
 * @link     https://github.com/jnjxp/jnjxp.purple
32
 */
33
class Queue implements IteratorAggregate, QueueInterface
34
{
35
    /**
36
     * Queue
37
     *
38
     * @var SplPriorityQueue
39
     *
40
     * @access protected
41
     */
42
    protected $queue;
43
44
    /**
45
     * __construct
46
     *
47
     * @access public
48
     */
49 1
    public function __construct()
50
    {
51
        $this->queue = new SplPriorityQueue;
52 1
    }
53
54
    /**
55
     * Count
56
     *
57
     * @return int
58
     *
59
     * @access public
60
     */
61
    public function count()
62
    {
63
        return count($this->queue);
64
    }
65
66
    /**
67
     * Insert
68
     *
69
     * @param mixed $value    value
70
     * @param mixed $priority order priority
71
     *
72
     * @return void
73
     *
74
     * @access public
75
     */
76
    public function insert($value, $priority)
77
    {
78
        $this->queue->insert($value, $priority);
79
    }
80
81
    /**
82
     * Get Iterator
83
     *
84
     * @return SplPriorityQueue
85
     *
86
     * @access public
87
     */
88
    public function getIterator()
89
    {
90
        return clone $this->queue;
91
    }
92
93
    /**
94
     * Clear
95
     *
96
     * @return void
97
     *
98
     * @access public
99
     */
100 1
    public function clear()
101
    {
102
        while (!$this->queue->isEmpty()) {
103
            $this->queue->next();
104
        }
105 1
    }
106
}
107