Merge pull request #24117 from civicrm/5.52
[civicrm-core.git] / CRM / Utils / File.php
index dbdcca1608e8f8a11b7709323855d515a3b1cef9..675709e9e63d05a7e293a923be7ae23e91da373d 100644 (file)
@@ -293,7 +293,7 @@ class CRM_Utils_File {
   }
 
   /**
-   * @param string|NULL $dsn
+   * @param string|null $dsn
    *   Use NULL to load the default/active connection from CRM_Core_DAO.
    *   Otherwise, give a full DSN string.
    * @param string $fileName
@@ -312,7 +312,7 @@ class CRM_Utils_File {
 
   /**
    *
-   * @param string|NULL $dsn
+   * @param string|null $dsn
    * @param string $queryString
    * @param string $prefix
    * @param bool $dieOnErrors
@@ -373,11 +373,11 @@ class CRM_Utils_File {
    *   stripped string
    */
   public static function stripComments($string) {
-    return preg_replace("/^(#|--).*\R*/m", "", $string);
+    return preg_replace("/^(#|--).*\R*/m", "", ($string ?? ''));
   }
 
   /**
-   * @param $ext
+   * @param string $ext
    *
    * @return bool
    */
@@ -446,9 +446,9 @@ class CRM_Utils_File {
     $uniqID = md5(uniqid(rand(), TRUE));
     $info = pathinfo($name);
     $basename = substr($info['basename'],
-      0, -(strlen(CRM_Utils_Array::value('extension', $info)) + (CRM_Utils_Array::value('extension', $info) == '' ? 0 : 1))
+      0, -(strlen(CRM_Utils_Array::value('extension', $info, '')) + (CRM_Utils_Array::value('extension', $info, '') == '' ? 0 : 1))
     );
-    if (!self::isExtensionSafe(CRM_Utils_Array::value('extension', $info))) {
+    if (!self::isExtensionSafe(CRM_Utils_Array::value('extension', $info, ''))) {
       // munge extension so it cannot have an embbeded dot in it
       // The maximum length of a filename for most filesystems is 255 chars.
       // We'll truncate at 240 to give some room for the extension.
@@ -1058,7 +1058,7 @@ HTACCESS;
     }
     $iconClasses = Civi::$statics[__CLASS__]['mimeIcons'];
     foreach ($iconClasses as $text => $icon) {
-      if (strpos($mimeType, $text) === 0) {
+      if (strpos(($mimeType ?? ''), $text) === 0) {
         return $icon;
       }
     }
@@ -1128,6 +1128,9 @@ HTACCESS;
    *   In php8 the return value from is_dir() is always bool but in php7 it can be null.
    */
   public static function isDir(?string $dir) {
+    if ($dir === NULL) {
+      return FALSE;
+    }
     set_error_handler(function($errno, $errstr) {
       // If this is open_basedir-related, convert it to an exception so we
       // can catch it.