Merge pull request #13993 from eileenmcnaughton/recur_fixes
[civicrm-core.git] / CRM / Utils / Type.php
index d45392353d4b799e2eb4d85ef4a0cec082313173..e2786712a420786e263ea190cd925d0c160516db 100644 (file)
@@ -158,7 +158,7 @@ class CRM_Utils_Type {
    *   An array of type in the form 'type name' => 'int representing type'
    */
   public static function getValidTypes() {
-    return array(
+    return [
       'Int' => self::T_INT,
       'String' => self::T_STRING,
       'Enum' => self::T_ENUM,
@@ -172,7 +172,7 @@ class CRM_Utils_Type {
       'Money' => self::T_MONEY,
       'Email' => self::T_EMAIL,
       'Mediumblob' => self::T_MEDIUMBLOB,
-    );
+    ];
   }
 
   /**
@@ -371,7 +371,7 @@ class CRM_Utils_Type {
 
             }
             // Normal clause.
-            $part = preg_replace_callback('/^(?:(?:((?:`[\w-]{1,64}`|[\w-]{1,64}))(?:\.))?(`[\w-]{1,64}`|[\w-]{1,64})(?: (asc|desc))?)$/i', array('CRM_Utils_Type', 'mysqlOrderByCallback'), trim($part));
+            $part = preg_replace_callback('/^(?:(?:((?:`[\w-]{1,64}`|[\w-]{1,64}))(?:\.))?(`[\w-]{1,64}`|[\w-]{1,64})(?: (asc|desc))?)$/i', ['CRM_Utils_Type', 'mysqlOrderByCallback'], trim($part));
           }
           return implode(', ', $parts);
         }
@@ -413,7 +413,7 @@ class CRM_Utils_Type {
    */
   public static function validate($data, $type, $abort = TRUE, $name = 'One of parameters ', $isThrowException = FALSE) {
 
-    $possibleTypes = array(
+    $possibleTypes = [
       'Integer',
       'Int',
       'Positive',
@@ -434,7 +434,8 @@ class CRM_Utils_Type {
       'ExtensionKey',
       'Json',
       'Alphanumeric',
-    );
+      'Color',
+    ];
     if (!in_array($type, $possibleTypes)) {
       if ($isThrowException) {
         throw new CRM_Core_Exception(ts('Invalid type, must be one of : ' . implode($possibleTypes)));
@@ -554,6 +555,12 @@ class CRM_Utils_Type {
           return $data;
         }
         break;
+
+      case 'Color':
+        if (CRM_Utils_Rule::color($data)) {
+          return $data;
+        }
+        break;
     }
 
     if ($abort) {
@@ -611,7 +618,7 @@ class CRM_Utils_Type {
    * @return array
    */
   public static function dataTypes() {
-    $types = array(
+    $types = [
       'Integer',
       'String',
       'Date',
@@ -619,7 +626,7 @@ class CRM_Utils_Type {
       'Timestamp',
       'Money',
       'Email',
-    );
+    ];
     return array_combine($types, $types);
   }