Test Failed
Push — master ( b17eba...69b436 )
by Kirill
06:37
created

Queue   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 0
dl 0
loc 51
ccs 0
cts 24
cp 0
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A push() 0 6 1
A getIterator() 0 6 2
A reduce() 0 10 3
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
    public function __construct()
26
    {
27
        $this->queue = new \SplQueue();
28
    }
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 array $args
53
     * @return \Generator
54
     */
55
    public function reduce(...$args): \Generator
56
    {
57
        foreach ($this->getIterator() as $item) {
58
            $output = $item(...$args);
59
60
            if ($output instanceof \Traversable) {
61
                yield $output;
62
            }
63
        }
64
    }
65
}
66