ProcessSearcher::searchByRegex()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 3
eloc 6
c 1
b 0
f 1
nc 3
nop 1
dl 0
loc 13
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