Completed
Push — master ( b7ef6a...58a002 )
by Kirill
03:12
created

Queue::extract()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
dl 0
loc 11
ccs 0
cts 7
cp 0
rs 9.9
c 0
b 0
f 0
cc 4
nc 3
nop 1
crap 20
1
<?php
2
/**
3
 * This file is part of Hydrogen package.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
declare(strict_types=1);
9
10
namespace RDS\Hydrogen\Processor;
11
12
/**
13
 * Class DeferredStack
14
 */
15
class Queue implements \IteratorAggregate
16
{
17
    /**
18
     * @var \SplQueue
19
     */
20
    private $queue;
21
22
    /**
23
     * Queue constructor.
24
     */
25 30
    public function __construct()
26
    {
27 30
        $this->queue = new \SplQueue();
28 30
    }
29
30
    /**
31
     * @param \Closure $deferred
32
     * @return Queue
33
     */
34
    public function push(\Closure $deferred): Queue
35
    {
36
        $this->queue->push($deferred);
37
38
        return $this;
39
    }
40
41
    /**
42
     * @return \Generator|\Closure[]
43
     */
44
    public function getIterator(): \Generator
45
    {
46
        while ($this->queue->count()) {
47
            yield $this->queue->pop();
48
        }
49
    }
50
51
    /**
52
     * @param mixed $value
53
     * @return void
54
     */
55 20
    public function invoke($value): void
56
    {
57 20
        foreach ($this->queue as $callback) {
58
            $callback($value);
59
        }
60 20
    }
61
}
62