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

PriorityQueue::insert()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 7
rs 9.4285
ccs 6
cts 6
cp 1
cc 2
eloc 4
nc 2
nop 2
crap 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