| Conditions | 3 |
| Paths | 3 |
| Total Lines | 17 |
| Code Lines | 9 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 9 |
| CRAP Score | 3.009 |
| Changes | 2 | ||
| Bugs | 1 | Features | 0 |
| 1 | <?php |
||
| 24 | 8 | public function writeFromReader(ResourceReader $reader, ResourceUri $target) |
|
| 25 | { |
||
| 26 | 8 | $targetResource = @fopen($target->getUri(), 'w+', true); |
|
| 27 | |||
| 28 | 8 | if (! is_resource($targetResource)) { |
|
| 29 | throw new \RuntimeException('Unable to open ' . $target->getUri() . ' for writing'); |
||
| 30 | } |
||
| 31 | |||
| 32 | 8 | $sourceResource = $reader->getContentsAsStream(); |
|
| 33 | 8 | $bytesCopied = @stream_copy_to_stream($sourceResource, $targetResource); |
|
| 34 | |||
| 35 | 8 | if ($bytesCopied <= 0) { |
|
| 36 | 4 | throw new \RuntimeException('Unable to write to ' . $target->getUri()); |
|
| 37 | }; |
||
| 38 | |||
| 39 | 4 | fclose($targetResource); |
|
| 40 | 4 | } |
|
| 41 | } |
||
| 42 |