Passed
Push — 0.6.x ( 9a1948...a98caa )
by Shinji
03:23 queued 01:32
created

CatFileReader::readAll()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 19
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 10
nc 1
nop 1
dl 0
loc 19
rs 9.9332
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * This file is part of the reliforp/reli-prof 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 Reli\Lib\File;
15
16
/**
17
 * workaround for a problem that PHP cannot open files in /proc/<pid>/root/
18
 */
19
final class CatFileReader implements FileReaderInterface
20
{
21
    public function readAll(string $path): string
22
    {
23
        /** @psalm-suppress InvalidArgument */
24
        $process = proc_open(
25
            [
26
                'cat',
27
                $path
28
            ],
29
            [
30
                0 => ['pipe', 'r'],
31
                1 => ['pipe', 'w'],
32
                2 => ['pipe', 'w'],
33
            ],
34
            $pipes
35
        );
36
        $contents = stream_get_contents($pipes[1]);
37
        proc_close($process);
38
39
        return $contents;
40
    }
41
}
42