Passed
Branch master (748c89)
by Schlaefer
02:28
created

MiddlewareQueue::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
nc 1
nop 0
dl 0
loc 3
c 0
b 0
f 0
cc 1
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
/**
3
 * @author  PhileCMS
4
 * @link    https://philecms.com
5
 * @license http://opensource.org/licenses/MIT
6
 */
7
8
namespace Phile\Http;
9
10
use IteratorAggregate;
11
use IteratorIterator;
12
use Psr\Http\Server\MiddlewareInterface;
13
use SplPriorityQueue;
14
use Traversable;
15
16
/**
17
 * Middleware queue
18
 */
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 5
    public function __construct()
30
    {
31 5
        $this->queue = new SplPriorityQueue();
32 5
    }
33
34
    /**
35
     * Adds middleware to queue
36
     *
37
     * @param MiddlewareInterface $middleware
38
     * @param int $priority
39
     * @return \self
0 ignored issues
show
Bug introduced by
The type self was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
40
     */
41 5
    public function add(MiddlewareInterface $middleware, int $priority = self::DEFAULT_PRIORITY): self
42
    {
43 5
        $this->queue->insert($middleware, [$priority, $this->serial--]);
44 5
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this returns the type Phile\Http\MiddlewareQueue which is incompatible with the documented return type self.
Loading history...
45
    }
46
47
    /**
48
     * Implements IteratorAggregate
49
     *
50
     * @return Traversable
51
     */
52 5
    public function getIterator(): Traversable
53
    {
54 5
        return new IteratorIterator($this->queue);
55
    }
56
}
57