CRM-13823 - Extract setLevel method from CRM_Utils_Check_Message constructor
[civicrm-core.git] / CRM / Utils / Check / Message.php
index 827613da60caf47cccad1274d1e2e9a75f4b7607..adf05e9530ad691dd90eca1331b29e5223172367 100644 (file)
@@ -96,16 +96,8 @@ class CRM_Utils_Check_Message {
     $this->name = $name;
     $this->message = $message;
     $this->title = $title;
-    // Convert level to integer
-    if (!CRM_Utils_Rule::positiveInteger($level)) {
-      $level = CRM_Utils_Check::severityMap($level);
-    }
-    else {
-      // Validate numeric input - this will throw an exception if invalid
-      CRM_Utils_Check::severityMap($level, TRUE);
-    }
-    $this->level = $level;
     $this->icon = $icon;
+    $this->setLevel($level);
   }
 
   /**
@@ -162,6 +154,26 @@ class CRM_Utils_Check_Message {
     $this->help = $help;
   }
 
+  /**
+   * Set severity level
+   *
+   * @param string|int $level
+   * @throws \CRM_Core_Exception
+   */
+  public function setLevel($level) {
+    // Convert level to integer
+    if (!CRM_Utils_Rule::positiveInteger($level)) {
+      $level = CRM_Utils_Check::severityMap($level);
+    }
+    else {
+      // Validate numeric input - this will throw an exception if invalid
+      CRM_Utils_Check::severityMap($level, TRUE);
+    }
+    $this->level = $level;
+    // Clear internal caches
+    unset($this->isVisible, $this->hiddenUntil);
+  }
+
   /**
    * Convert to array.
    *