Add stricter wrapper around unlink()

This commit is contained in:
Joshua Ramon Enslin 2021-01-06 12:49:35 +01:00
parent d28c245a1a
commit 298e2238a8
Signed by: jrenslin
GPG Key ID: 46016F84501B70AE

View File

@ -62,7 +62,7 @@ final class MD_STD {
*
* @return void
*/
public static function mkdir(string $pathname, int $mode = 0775, bool $recursive = false) {
public static function mkdir(string $pathname, int $mode = 0775, bool $recursive = false):void {
if (\mkdir($pathname, $mode, $recursive) === false) {
throw new Exception("Failed to create directory: $pathname");
@ -70,6 +70,24 @@ final class MD_STD {
}
/**
* Wrapper around unlink, that throws an exception if the file failed to be
* removed.
*
* @see https://www.php.net/manual/en/function.unlink.php
*
* @param string $filename File path.
*
* @return void
*/
public static function unlink(string $filename):void {
if (\unlink($filename) === false) {
throw new Exception("Failed to delete: $filename");
}
}
/**
* Gets contents of a folder.
*