Avoid CiviCRM running full drupal cache flush, as this results in CiviCRM clobbering...
[civicrm-core.git] / CRM / Utils / Type.php
index af4082058adf1b219bee3f9018a3bc0f39dbcd52..8219909a2482c77fba1a2c9820a5200a4df5d899 100644 (file)
@@ -3,7 +3,7 @@
  +--------------------------------------------------------------------+
  | CiviCRM version 4.6                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2014                                |
+ | Copyright CiviCRM LLC (c) 2004-2015                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
  | GNU Affero General Public License or the licensing of CiviCRM,     |
  | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
  +--------------------------------------------------------------------+
-*/
+ */
 
 /**
  *
  * @package CRM
- * @copyright CiviCRM LLC (c) 2004-2014
+ * @copyright CiviCRM LLC (c) 2004-2015
  * $Id: $
  *
  */
 class CRM_Utils_Type {
   const
-    T_INT        = 1,
-    T_STRING     = 2,
-    T_ENUM       = 2,
-    T_DATE       = 4,
-    T_TIME       = 8,
-    T_BOOLEAN    = 16,
-    T_TEXT       = 32,
-    T_LONGTEXT   = 32,
-    T_BLOB       = 64,
-    T_TIMESTAMP  = 256,
-    T_FLOAT      = 512,
-    T_MONEY      = 1024,
-    T_EMAIL      = 2048,
-    T_URL        = 4096,
-    T_CCNUM      = 8192,
+    T_INT = 1,
+    T_STRING = 2,
+    T_ENUM = 2,
+    T_DATE = 4,
+    T_TIME = 8,
+    T_BOOLEAN = 16,
+    T_TEXT = 32,
+    T_LONGTEXT = 32,
+    T_BLOB = 64,
+    T_TIMESTAMP = 256,
+    T_FLOAT = 512,
+    T_MONEY = 1024,
+    T_EMAIL = 2048,
+    T_URL = 4096,
+    T_CCNUM = 8192,
     T_MEDIUMBLOB = 16384;
 
   // @todo What's the point of these constants? Backwards compatibility?
   const
-    TWO       = 2,
-    FOUR      = 4,
-    SIX       = 6,
-    EIGHT     = 8,
-    TWELVE    = 12,
-    SIXTEEN   = 16,
-    TWENTY    = 20,
-    MEDIUM    = 20,
-    THIRTY    = 30,
-    BIG       = 30,
+    TWO = 2,
+    FOUR = 4,
+    SIX = 6,
+    EIGHT = 8,
+    TWELVE = 12,
+    SIXTEEN = 16,
+    TWENTY = 20,
+    MEDIUM = 20,
+    THIRTY = 30,
+    BIG = 30,
     FORTYFIVE = 45,
-    HUGE      = 45;
+    HUGE = 45;
 
   /**
    * Gets the string representation for a data type.
@@ -112,7 +112,7 @@ class CRM_Utils_Type {
         $string = 'Blob';
         break;
 
-        // CRM-10404
+      // CRM-10404
       case 12:
       case 256:
         $string = 'Timestamp';
@@ -149,7 +149,7 @@ class CRM_Utils_Type {
    *   The value to be verified/escaped.
    * @param string $type
    *   The type to verify against.
-   * @param boolean $abort
+   * @param bool $abort
    *   If TRUE, the operation will CRM_Core_Error::fatal() on invalid data.
    *
    * @return mixed
@@ -160,12 +160,12 @@ class CRM_Utils_Type {
       case 'Integer':
       case 'Int':
         if (CRM_Utils_Rule::integer($data)) {
-          return $data;
+          return (int) $data;
         }
         break;
 
       case 'Positive':
-      // CRM-8925 the 3 below are for custom fields of this type
+        // CRM-8925 the 3 below are for custom fields of this type
       case 'Country':
       case 'StateProvince':
         // Checked for multi valued state/country value
@@ -185,7 +185,7 @@ class CRM_Utils_Type {
             return $data;
           }
         }
-        elseif (!is_numeric($data) &&  CRM_Core_DAO::escapeString($data)) {
+        elseif (!is_numeric($data) && CRM_Core_DAO::escapeString($data)) {
           return $data;
         }
         elseif (CRM_Utils_Rule::positiveInteger($data)) {
@@ -250,7 +250,9 @@ class CRM_Utils_Type {
         break;
 
       default:
-        CRM_Core_Error::fatal("Cannot recognize $type for $data");
+        CRM_Core_Error::fatal(
+          $type . " is not a recognised (camel cased) data type."
+        );
         break;
     }
 
@@ -263,13 +265,13 @@ class CRM_Utils_Type {
   }
 
   /**
-   * Verify that a variable is of a given type
+   * Verify that a variable is of a given type.
    *
    * @param mixed $data
    *   The value to validate.
    * @param string $type
    *   The type to validate against.
-   * @param boolean $abort
+   * @param bool $abort
    *   If TRUE, the operation will CRM_Core_Error::fatal() on invalid data.
    * @name string $name
    *   The name of the attribute
@@ -282,7 +284,7 @@ class CRM_Utils_Type {
       case 'Integer':
       case 'Int':
         if (CRM_Utils_Rule::integer($data)) {
-          return $data;
+          return (int) $data;
         }
         break;
 
@@ -362,4 +364,5 @@ class CRM_Utils_Type {
 
     return NULL;
   }
+
 }