Completed
Push — master ( fc6b0c...d75285 )
by Shinji
12s queued 10s
created

TraceLoopProvider::getMainLoop()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 5
nc 1
nop 2
dl 0
loc 7
rs 10
c 1
b 0
f 1
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\Command\Inspector;
15
16
use PhpProfiler\Lib\Loop\Loop;
17
use PhpProfiler\Lib\Loop\LoopBuilder;
18
use PhpProfiler\Lib\Loop\LoopProcess\CallableLoop;
19
use PhpProfiler\Lib\Loop\LoopProcess\KeyboardCancelLoop;
20
use PhpProfiler\Lib\Loop\LoopProcess\NanoSleepLoop;
21
use PhpProfiler\Lib\Loop\LoopProcess\RetryOnExceptionLoop;
22
use PhpProfiler\Lib\Process\MemoryReader\MemoryReaderException;
23
24
final class TraceLoopProvider
25
{
26
    private LoopBuilder $loop_builder;
27
28
    public function __construct(LoopBuilder $loop_builder)
29
    {
30
        $this->loop_builder = $loop_builder;
31
    }
32
33
    public function getMainLoop(callable $main, int $sleep_nano_seconds): Loop
34
    {
35
        return $this->loop_builder->addProcess(NanoSleepLoop::class, [$sleep_nano_seconds])
36
            ->addProcess(RetryOnExceptionLoop::class, [10, [MemoryReaderException::class]])
37
            ->addProcess(KeyboardCancelLoop::class, ['q'])
38
            ->addProcess(CallableLoop::class, [$main])
39
            ->build();
40
    }
41
}
42