Completed
Pull Request — master (#11)
by adev
04:33
created

PriorityQueue   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 12
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
c 1
b 0
f 0
lcom 1
cbo 0
dl 0
loc 12
rs 10
ccs 6
cts 6
cp 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A insert() 0 7 2
1
<?php
2
3
namespace Port\Steps;
4
5
/**
6
 * Overrides \SplPriorityQueue in order to enforcing predictable queue order for elements with the same priority
7
 *
8
 * @see https://bugs.php.net/bug.php?id=53710
9
 * @see https://mwop.net/blog/253-Taming-SplPriorityQueue.html
10
 */
11
class PriorityQueue extends \SplPriorityQueue
12
{
13
    private $queueOrder = PHP_INT_MAX;
14
15 6
    public function insert($value, $priority)
16
    {
17 6
        if (is_int($priority)) {
18 6
            $priority = [$priority, $this->queueOrder--];
19 6
        }
20 6
        parent::insert($value, $priority);
21 6
    }
22
}
23