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