Passed
Pull Request — master (#9)
by Shinji
01:26
created

ProcessSearcher   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A searchByRegex() 0 11 3
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\Process\ProcFileSystem\CommandLineEnumerator;
17
18
final class ProcessSearcher
19
{
20
    /**
21
     * @param string $regex
22
     * @return int[]
23
     */
24
    public function searchByRegex(string $regex): array
25
    {
26
        $result = [];
27
28
        foreach (new CommandLineEnumerator() as $pid => $command_line) {
29
            if (preg_match($regex, $command_line)) {
30
                $result[] = $pid;
31
            }
32
        }
33
34
        return $result;
35
    }
36
}
37