Completed
Branch master (5b2ca7)
by Hong
38:44 queued 37:42
created

UniquePriorityQueue::getIterator()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
/**
4
 * Phoole (PHP7.2+)
5
 *
6
 * @category  Library
7
 * @package   Phoole\Base
8
 * @copyright Copyright (c) 2019 Hong Zhang
9
 */
10
declare(strict_types=1);
11
12
namespace Phoole\Base\Queue;
13
14
/**
15
 * UniquePriorityQueue
16
 *
17
 * Make sure items in the queue are unique
18
 *
19
 * @package Phoole\Base
20
 */
21
class UniquePriorityQueue extends PriorityQueue
22
{
23
    /**
24
     * {@inheritDoc}
25
     */
26
    public function count()
27
    {
28
        return count(array_unique(array_column($this->queue, 'data'), \SORT_REGULAR));
29
    }
30
31
    /**
32
     * {@inheritDoc}
33
     */
34
    public function getIterator()
35
    {
36
        $this->sortQueue();
37
        return new \ArrayIterator(
38
            array_unique(array_column($this->queue, 'data'), \SORT_REGULAR)
39
        );
40
    }
41
}
42