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

UniquePriorityQueue   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 1
dl 0
loc 21
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A count() 0 4 1
A getIterator() 0 7 1
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