Declare CRM_Core_Exception in cleanDir
authorEileen McNaughton <emcnaughton@wikimedia.org>
Tue, 5 Sep 2023 05:20:49 +0000 (17:20 +1200)
committerEileen McNaughton <emcnaughton@wikimedia.org>
Tue, 5 Sep 2023 05:25:39 +0000 (17:25 +1200)
The only information our exception imparts is that it is
coming from CiviCRM Core  - but we should at least be consistent in that.

Also - I think passing something other than a string here would be bad - so
adding a type hint is good. We were already checking not target so the empty string check is redundant

CRM/Utils/File.php

index cdea5b63af8f3148072437263401b3ac716bf549..37f2522a430ab1cd8fb27200b63dbc70e6116fa4 100644 (file)
@@ -90,12 +90,12 @@ class CRM_Utils_File {
    * @param bool $rmdir
    * @param bool $verbose
    *
-   * @throws Exception
+   * @throws \CRM_Core_Exception
    */
-  public static function cleanDir($target, $rmdir = TRUE, $verbose = TRUE) {
+  public static function cleanDir(string $target, bool $rmdir = TRUE, bool $verbose = TRUE) {
     static $exceptions = ['.', '..'];
-    if ($target == '' || $target == '/' || !$target) {
-      throw new Exception("Overly broad deletion");
+    if (!$target || $target === '/') {
+      throw new CRM_Core_Exception('Overly broad deletion');
     }
 
     if ($dh = @opendir($target)) {
@@ -894,8 +894,8 @@ HTACCESS;
       case 'image/x-png':
       case 'image/png':
       case 'image/jpg':
-        list($imageWidth, $imageHeight) = getimagesize($path);
-        list($imageThumbWidth, $imageThumbHeight) = CRM_Contact_BAO_Contact::getThumbSize($imageWidth, $imageHeight);
+        [$imageWidth, $imageHeight] = getimagesize($path);
+        [$imageThumbWidth, $imageThumbHeight] = CRM_Contact_BAO_Contact::getThumbSize($imageWidth, $imageHeight);
         $url = "<a href=\"$url\" class='crm-image-popup'>
           <img src=\"$url\" width=$imageThumbWidth height=$imageThumbHeight/>
           </a>";