Passed
Push — master ( a5c131...325eda )
by Shinji
01:37
created

CatFileReader::readAll()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 19
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 10
nc 1
nop 1
dl 0
loc 19
rs 9.9332
c 1
b 0
f 1
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\File;
15
16
/**
17
 * Class CatFileReader
18
 *
19
 * workaround for a problem that PHP cannot open files in /proc/<pid>/root/
20
 *
21
 * @package PhpProfiler\Lib\File
22
 */
23
final class CatFileReader implements FileReaderInterface
24
{
25
    /**
26
     * @param string $path
27
     * @return string
28
     */
29
    public function readAll(string $path): string
30
    {
31
        /** @psalm-suppress InvalidArgument */
32
        $process = proc_open(
33
            [
0 ignored issues
show
Bug introduced by
array('cat', $path) of type array<integer,string> is incompatible with the type string expected by parameter $cmd of proc_open(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

33
            /** @scrutinizer ignore-type */ [
Loading history...
34
                'cat',
35
                $path
36
            ],
37
            [
38
                0 => ['pipe', 'r'],
39
                1 => ['pipe', 'w'],
40
                2 => ['pipe', 'w'],
41
            ],
42
            $pipes
43
        );
44
        $contents = stream_get_contents($pipes[1]);
45
        proc_close($process);
0 ignored issues
show
Bug introduced by
It seems like $process can also be of type false; however, parameter $process of proc_close() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

45
        proc_close(/** @scrutinizer ignore-type */ $process);
Loading history...
46
47
        return $contents;
48
    }
49
}
50