Passed
Push — master ( e847fb...cefdd7 )
by Shinji
03:11 queued 01:31
created

ProcessSearcher::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
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 1
dl 0
loc 3
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
19
final class ProcessSearcher implements ProcessSearcherInterface
20
{
21
    public function __construct(
22
        private FileReaderInterface $file_reader
23
    ) {
24
    }
25
26
    /**
27
     * @param string $regex
28
     * @return int[]
29
     */
30
    public function searchByRegex(string $regex): array
31
    {
32
        $result = [];
33
34
        foreach (new CommandLineEnumerator($this->file_reader) as $pid => $command_line) {
35
            if (preg_match($regex, $command_line)) {
36
                $result[] = $pid;
37
            }
38
        }
39
40
        return $result;
41
    }
42
}
43