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