Total Complexity | 9 |
Total Lines | 36 |
Duplicated Lines | 0 % |
Changes | 2 | ||
Bugs | 1 | Features | 0 |
1 | <?php |
||
19 | class StreamFactory implements StreamFactoryInterface{ |
||
20 | |||
21 | /** |
||
22 | * @inheritDoc |
||
23 | */ |
||
24 | public function createStream(string $content = ''):StreamInterface{ |
||
32 | } |
||
33 | |||
34 | /** |
||
35 | * @inheritDoc |
||
36 | */ |
||
37 | public function createStreamFromFile(string $filename, string $mode = 'r'):StreamInterface{ |
||
38 | |||
39 | if(empty($filename) || !is_file($filename) || !is_readable($filename)){ |
||
40 | throw new RuntimeException('invalid file'); |
||
41 | } |
||
42 | |||
43 | if(!in_array($mode, FactoryHelpers::STREAM_MODES_WRITE) && !in_array($mode, FactoryHelpers::STREAM_MODES_READ)){ |
||
44 | throw new InvalidArgumentException('invalid mode'); |
||
45 | } |
||
46 | |||
47 | return new Stream(fopen($filename, $mode)); |
||
48 | } |
||
49 | |||
50 | /** |
||
51 | * @inheritDoc |
||
52 | */ |
||
53 | public function createStreamFromResource($resource):StreamInterface{ |
||
55 | } |
||
56 | |||
58 |