| 1 | <?php |
||
| 19 | trait PriorityQueueTrait |
||
| 20 | { |
||
| 21 | /** |
||
| 22 | * data storage |
||
| 23 | * |
||
| 24 | * @var array |
||
| 25 | */ |
||
| 26 | protected $queue = []; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * marker for sorted or not |
||
| 30 | * |
||
| 31 | * @var bool |
||
| 32 | */ |
||
| 33 | protected $sorted = true; |
||
| 34 | |||
| 35 | /** |
||
| 36 | * counter for priority |
||
| 37 | * |
||
| 38 | * @var int |
||
| 39 | */ |
||
| 40 | protected $counter = 20000000; |
||
| 41 | |||
| 42 | /** |
||
| 43 | * {@inheritDoc} |
||
| 44 | */ |
||
| 45 | public function insert($data, int $priority = 0): void |
||
| 51 | |||
| 52 | /** |
||
| 53 | * {@inheritDoc} |
||
| 54 | */ |
||
| 55 | public function combine(PriorityQueueInterface $queue): PriorityQueueInterface |
||
| 63 | |||
| 64 | /** |
||
| 65 | * {@inheritDoc} |
||
| 66 | */ |
||
| 67 | public function count() |
||
| 71 | |||
| 72 | /** |
||
| 73 | * {@inheritDoc} |
||
| 74 | */ |
||
| 75 | public function getIterator() |
||
| 80 | |||
| 81 | /** |
||
| 82 | * Generate an integer key |
||
| 83 | * |
||
| 84 | * @param int $priority |
||
| 85 | * @throws \RuntimeException priority out of range |
||
| 86 | * @return int |
||
| 87 | */ |
||
| 88 | protected function getIndex(int $priority): int |
||
| 95 | |||
| 96 | /** |
||
| 97 | * Sort the queue from higher to lower int $key |
||
| 98 | * |
||
| 99 | * @return $this |
||
| 100 | */ |
||
| 101 | protected function sortQueue() |
||
| 109 | } |
||
| 110 |
If you access a property on an interface, you most likely code against a concrete implementation of the interface.
Available Fixes
Adding an additional type check:
Changing the type hint: