ProcessSearcher::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 0
c 0
b 0
f 0
nc 1
nop 2
dl 0
loc 4
rs 10
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\Process\Search;
15
16
use PhpProfiler\Lib\File\FileReaderInterface;
17
use PhpProfiler\Lib\Process\ProcFileSystem\CommandLineEnumerator;
18
use PhpProfiler\Lib\Process\ProcFileSystem\ThreadEnumerator;
19
20
final class ProcessSearcher implements ProcessSearcherInterface
21
{
22
    public function __construct(
23
        private FileReaderInterface $file_reader,
24
        private ThreadEnumerator $thread_enumerator,
25
    ) {
26
    }
27
28
    /** @return int[] */
29
    public function searchByRegex(string $regex): array
30
    {
31
        $result = [];
32
33
        foreach (new CommandLineEnumerator($this->file_reader) as $pid => $command_line) {
34
            if (preg_match($regex, $command_line)) {
35
                $result = \array_merge($result, iterator_to_array(
36
                    $this->thread_enumerator->getThreadIds($pid)
37
                ));
38
            }
39
        }
40
41
        return $result;
42
    }
43
}
44