Conditions | 4 |
Paths | 4 |
Total Lines | 16 |
Code Lines | 9 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
18 | public function saveToFile(Estimator $estimator, string $filepath) |
||
19 | { |
||
20 | if (!is_writable(dirname($filepath))) { |
||
21 | throw FileException::cantSaveFile(basename($filepath)); |
||
22 | } |
||
23 | |||
24 | $serialized = serialize($estimator); |
||
25 | if (empty($serialized)) { |
||
26 | throw SerializeException::cantSerialize(get_type($estimator)); |
||
27 | } |
||
28 | |||
29 | $result = file_put_contents($filepath, $serialized, LOCK_EX); |
||
30 | if ($result === false) { |
||
31 | throw FileException::cantSaveFile(basename($filepath)); |
||
32 | } |
||
33 | } |
||
34 | |||
55 |