Conditions | 4 |
Paths | 3 |
Total Lines | 12 |
Code Lines | 6 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
20 | public function createStreamFromFile(string $filename, string $mode = 'r'): StreamInterface |
||
21 | { |
||
22 | $resource = @fopen($filename, $mode); |
||
23 | if ($resource === false) { |
||
24 | if ($mode === '' || in_array($mode[0], ['r', 'w', 'a', 'x', 'c'], true) === false) { |
||
25 | throw new \InvalidArgumentException('The mode ' . $mode . ' is invalid.', 1566823434); |
||
26 | } |
||
27 | |||
28 | throw new \RuntimeException('The file ' . $filename . ' cannot be opened.', 1566823435); |
||
29 | } |
||
30 | |||
31 | return new Stream($resource); |
||
32 | } |
||
42 |