Passed
Push — master ( c1005b...956cce )
by Shinji
12:20 queued 10:15
created

ThreadEnumerator::getThreadIds()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 14
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 4
eloc 6
c 1
b 1
f 0
nc 4
nop 1
dl 0
loc 14
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\ProcFileSystem;
15
16
final class ThreadEnumerator
17
{
18
    /** @return \Generator<int> */
19
    public function getThreadIds(int $pid)
20
    {
21
        /**
22
         * @var string $full_path
23
         * @var \SplFileInfo $item
24
         */
25
        foreach (new \DirectoryIterator("/proc/{$pid}/task/") as $item) {
26
            if (file_exists($item->getPathname()) === false) {
27
                continue;
28
            }
29
            if (!is_numeric(basename($item->getPathname()))) {
30
                continue;
31
            }
32
            yield (int)basename($item->getPathname());
33
        }
34
    }
35
}
36