Passed
Pull Request — master (#8)
by Shinji
08:28
created

TraceLoopProvider   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A getMainLoop() 0 7 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