Lines
100.00%
3 / 3
Functions and Methods
100.00%
2 / 2
Classes and Traits
100.00%
1 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| SnapshotFileWriter | 100.00% | 3 / 3 | 100.00% | 2 / 2 | 3 | 100.00% | 1 / 1 | |||
| __construct | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | |||||
| writeSnapshot | 100.00% | 2 / 2 | 100.00% | 1 / 1 | 2 | |||||
| 1 | <?php | |
| 2 | ||
| 3 | declare(strict_types=1); | |
| 4 | ||
| 5 | namespace Stewart\Codegen\Snapshot; | |
| 6 | ||
| 7 | use Stewart\Codegen\Exception\CodegenException; | |
| 8 | ||
| 9 | final readonly class SnapshotFileWriter | |
| 10 | { | |
| 11 | public function __construct(private SnapshotCodec $codec) {} | |
| 12 | ||
| 13 | /** @throws CodegenException */ | |
| 14 | public function writeSnapshot(string $path, Snapshot $snapshot): void | |
| 15 | { | |
| 16 | if (file_put_contents($path, $this->codec->encodeSnapshot($snapshot)) === false) { | |
| 17 | throw CodegenException::fileNotWritable($path); | |
| 18 | } | |
| 19 | } | |
| 20 | } |