summaryrefslogtreecommitdiffstats
path: root/inc/fileutil.inc.php
diff options
context:
space:
mode:
Diffstat (limited to 'inc/fileutil.inc.php')
-rw-r--r--inc/fileutil.inc.php18
1 files changed, 10 insertions, 8 deletions
diff --git a/inc/fileutil.inc.php b/inc/fileutil.inc.php
index f35f987e..e986b2de 100644
--- a/inc/fileutil.inc.php
+++ b/inc/fileutil.inc.php
@@ -1,5 +1,7 @@
<?php
+declare(strict_types=1);
+
class FileUtil
{
@@ -8,9 +10,9 @@ class FileUtil
*
* @param string $file file to read
* @param int $maxBytes maximum length to read
- * @return boolean|string data, false on error
+ * @return false|string data, false on error
*/
- public static function readFile($file, $maxBytes = 1000)
+ public static function readFile(string $file, int $maxBytes = 1000)
{
$fh = @fopen($file, 'rb');
if ($fh === false)
@@ -19,18 +21,18 @@ class FileUtil
fclose($fh);
return $data;
}
-
+
/**
* Read a file of key=value lines to assoc array.
*
* @param string $file Filename
- * @return boolean|array assoc array, false on error
+ * @return ?array assoc array, null on error
*/
- public static function fileToArray($file)
+ public static function fileToArray(string $file): ?array
{
$data = self::readFile($file, 2000);
if ($data === false)
- return false;
+ return null;
$data = explode("\n", str_replace("\r", "\n", $data));
$ret = array();
foreach ($data as $line) {
@@ -40,7 +42,7 @@ class FileUtil
}
return $ret;
}
-
+
/**
* Write given associative array to file as key=value pairs.
*
@@ -48,7 +50,7 @@ class FileUtil
* @param array $array Associative array to write
* @return boolean success of operation
*/
- public static function arrayToFile($file, $array)
+ public static function arrayToFile(string $file, array $array): bool
{
$fh = fopen($file, 'wb');
if ($fh === false)