| Total Complexity | 3 |
| Total Lines | 36 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 19 | class MiddlewareQueue implements IteratorAggregate |
||
| 20 | { |
||
| 21 | public const DEFAULT_PRIORITY = 100; |
||
| 22 | |||
| 23 | /** @var int counter for FIFO order for items with same priority */ |
||
| 24 | protected $serial = PHP_INT_MAX; |
||
| 25 | |||
| 26 | /** @var SplPriorityQueue middleware */ |
||
| 27 | protected $queue; |
||
| 28 | |||
| 29 | 8 | public function __construct() |
|
| 32 | } |
||
| 33 | |||
| 34 | /** |
||
| 35 | * Adds middleware to queue |
||
| 36 | * |
||
| 37 | * @param MiddlewareInterface $middleware |
||
| 38 | * @param int $priority |
||
| 39 | * @return self |
||
| 40 | */ |
||
| 41 | 8 | public function add(MiddlewareInterface $middleware, int $priority = self::DEFAULT_PRIORITY): self |
|
| 42 | { |
||
| 43 | 8 | $this->queue->insert($middleware, [$priority, $this->serial--]); |
|
| 44 | 8 | return $this; |
|
| 45 | } |
||
| 46 | |||
| 47 | /** |
||
| 48 | * Implements IteratorAggregate |
||
| 49 | * |
||
| 50 | * @return \Iterator |
||
| 51 | */ |
||
| 52 | 8 | public function getIterator(): Iterator |
|
| 55 | } |
||
| 56 | } |
||
| 57 |