PhpSearcherEntryPoint   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 25
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A run() 0 17 2
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\Inspector\Daemon\Searcher\Worker;
15
16
use PhpProfiler\Inspector\Daemon\Searcher\Protocol\Message\UpdateTargetProcessMessage;
17
use PhpProfiler\Inspector\Daemon\Dispatcher\TargetProcessList;
18
use PhpProfiler\Inspector\Daemon\Searcher\Protocol\Message\TargetRegexMessage;
19
use PhpProfiler\Inspector\Daemon\Searcher\Protocol\PhpSearcherWorkerProtocolInterface;
20
use PhpProfiler\Lib\Amphp\WorkerEntryPointInterface;
21
use PhpProfiler\Lib\Process\Search\ProcessSearcherInterface;
22
23
use function sleep;
24
25
final class PhpSearcherEntryPoint implements WorkerEntryPointInterface
26
{
27
    public function __construct(
28
        private PhpSearcherWorkerProtocolInterface $protocol,
29
        private ProcessSearcherInterface $process_searcher
30
    ) {
31
    }
32
33
    public function run(): \Generator
34
    {
35
        /**
36
         * @psalm-ignore-var
37
         * @var TargetRegexMessage $target_regex
38
         */
39
        $target_regex = yield $this->protocol->receiveTargetRegex();
40
41
        while (1) {
42
            yield $this->protocol->sendUpdateTargetProcess(
43
                new UpdateTargetProcessMessage(
44
                    new TargetProcessList(
45
                        ...$this->process_searcher->searchByRegex($target_regex->regex)
46
                    )
47
                )
48
            );
49
            sleep(1);
50
        }
51
    }
52
}
53