PipeLine   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 47
rs 10
c 0
b 0
f 0
ccs 22
cts 22
cp 1
wmc 9
lcom 1
cbo 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A current() 0 4 1
A insert() 0 15 4
A next() 0 4 1
A valid() 0 4 1
A count() 0 4 1
A rewind() 0 4 1
1
<?php
2
declare(strict_types=1);
3
4
namespace SlayerBirden\DataFlow;
5
6
class PipeLine implements PipeLineInterface, \Countable
7
{
8
    private $queue = [];
9
    private $pointer = 0;
10
    private $queueOrder = PHP_INT_MAX;
11
12 6
    public function current(): PipeInterface
13
    {
14 6
        return $this->queue[$this->pointer]['item'];
15
    }
16
17 8
    public function insert(PipeInterface $handler, int $priority = 0): void
18
    {
19 8
        $this->queue[] = [
20 8
            'item' => $handler,
21 8
            'p' => $priority,
22 8
            '_p' => $this->queueOrder--,
23
        ];
24
        usort($this->queue, function ($itemA, $itemB) {
25 8
            if ($itemA['p'] == $itemB['p']) {
26 5
                return ($itemA['_p'] > $itemB['_p']) ? -1 : 1;
27
            }
28
29 3
            return ($itemA['p'] > $itemB['p']) ? -1 : 1;
30 8
        });
31 8
    }
32
33 5
    public function next(): void
34
    {
35 5
        $this->pointer++;
36 5
    }
37
38 4
    public function valid(): bool
39
    {
40 4
        return isset($this->queue[$this->pointer]);
41
    }
42
43 1
    public function count(): int
44
    {
45 1
        return count($this->queue);
46
    }
47
48 5
    public function rewind(): void
49
    {
50 5
        $this->pointer = 0;
51 5
    }
52
}
53