From 25b3138a268673c64f41119e7e8e62262c771e7f Mon Sep 17 00:00:00 2001 From: Joshua Ramon Enslin Date: Sat, 22 Aug 2020 17:00:21 +0200 Subject: [PATCH] Add type-safe wrapper around MD_STD --- MD_STD.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/MD_STD.php b/MD_STD.php index 9ed4f00..f49055c 100644 --- a/MD_STD.php +++ b/MD_STD.php @@ -284,6 +284,25 @@ class MD_STD { } + /** + * Type-safe wrapper around filesize, if output is false, throws an error. + * + * @param string $filename File name. + * + * @return integer + */ + public static function filesize(string $filename):int { + + $output = filesize($filename); + + if ($output === false) { + throw new Exception("Cannot get filesize of file {$filename}"); + } + + return $output; + + } + /** * Function human_filesize translates byte-level filesizes to human readable ones. * Thanks to Jeffrey Sambells http://jeffreysambells.com/2012/10/25/human-readable-filesize-php