Passed
Pull Request — master (#9)
by Shinji
10:53
created

AsyncLoop   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 8
dl 0
loc 17
c 1
b 0
f 1
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A invoke() 0 8 3
1
<?php
2
3
/**
4
 * This file is part of the sj-i/php-profiler package.
5
 *
6
 * (c) sji <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace PhpProfiler\Lib\Loop;
15
16
final class AsyncLoop
17
{
18
    private AsyncLoopMiddlewareInterface $process;
19
20
    public function __construct(AsyncLoopMiddlewareInterface $process)
21
    {
22
        $this->process = $process;
23
    }
24
25
    public function invoke(): \Generator
26
    {
27
        while (1) {
28
            $result = $this->process->invoke();
29
            if (!$result->valid()) {
30
                break;
31
            }
32
            yield from $result;
33
        }
34
    }
35
}
36