INFRA-132 - CRM/Core - Misc
[civicrm-core.git] / CRM / Core / Error.php
index e6b543fac9b7b6426449ade8972164310bb51cbf..a0a2d99409957f454d11353853148451f364aadf 100644 (file)
@@ -114,7 +114,7 @@ class CRM_Core_Error extends PEAR_ErrorStack {
    * @return object
    * @static
    */
-   public static function &singleton($package = NULL, $msgCallback = FALSE, $contextCallback = FALSE, $throwPEAR_Error = FALSE, $stackClass = 'PEAR_ErrorStack') {
+  public static function &singleton($package = NULL, $msgCallback = FALSE, $contextCallback = FALSE, $throwPEAR_Error = FALSE, $stackClass = 'PEAR_ErrorStack') {
     if (self::$_singleton === NULL) {
       self::$_singleton = new CRM_Core_Error('CiviCRM');
     }
@@ -299,9 +299,12 @@ class CRM_Core_Error extends PEAR_ErrorStack {
   /**
    * Display an error page with an error message describing what happened
    *
-   * @param string $message the error message
-   * @param string $code the error code if any
-   * @param string $email the email address to notify of this situation
+   * @param string $message
+   *   The error message.
+   * @param string $code
+   *   The error code if any.
+   * @param string $email
+   *   The email address to notify of this situation.
    *
    * @throws Exception
    *
@@ -322,7 +325,7 @@ class CRM_Core_Error extends PEAR_ErrorStack {
       $details = 'A fatal error was triggered';
       if ($message) {
         $details .= ': ' . $message;
-    }
+      }
       throw new Exception($details, $code);
     }
 
@@ -465,11 +468,11 @@ class CRM_Core_Error extends PEAR_ErrorStack {
    * Outputs pre-formatted debug information. Flushes the buffers
    * so we can interrupt a potential POST/redirect
    *
-   * @param  string name of debug section
-   * @param  mixed  reference to variables that we need a trace of
-   * @param  bool   should we log or return the output
-   * @param  bool   whether to generate a HTML-escaped output
-   * @param  bool   should we check permissions before displaying output
+   * @param string name of debug section
+   * @param mixed reference to variables that we need a trace of
+   * @param bool should we log or return the output
+   * @param bool whether to generate a HTML-escaped output
+   * @param bool should we check permissions before displaying output
    *                useful when we die during initialization and permissioning
    *                subsystem is not initialized - CRM-13765
    *
@@ -515,9 +518,12 @@ class CRM_Core_Error extends PEAR_ErrorStack {
    *
    * @param string $variable_name
    * @param mixed $variable
-   * @param bool $print should we use print_r ? (else we use var_dump)
-   * @param bool $log should we log or return the output
-   * @param string $comp variable name
+   * @param bool $print
+   *   Should we use print_r ? (else we use var_dump).
+   * @param bool $log
+   *   Should we log or return the output.
+   * @param string $comp
+   *   Variable name.
    *
    * @return string the generated output
    *
@@ -527,11 +533,12 @@ class CRM_Core_Error extends PEAR_ErrorStack {
    * @see CRM_Core_Error::debug()
    * @see CRM_Core_Error::debug_log_message()
    */
-  static function debug_var($variable_name,
+  static function debug_var(
+    $variable_name,
     $variable,
     $print = TRUE,
-    $log   = TRUE,
-    $comp  = ''
+    $log = TRUE,
+    $comp = ''
   ) {
     // check if variable is set
     if (!isset($variable)) {
@@ -562,9 +569,11 @@ class CRM_Core_Error extends PEAR_ErrorStack {
    * Display the error message on terminal
    *
    * @param $message
-   * @param bool $out should we log or return the output
+   * @param bool $out
+   *   Should we log or return the output.
    *
-   * @param string $comp message to be output
+   * @param string $comp
+   *   Message to be output.
    * @return string format of the backtrace
    *
    *
@@ -597,9 +606,9 @@ class CRM_Core_Error extends PEAR_ErrorStack {
   public static function debug_query($string) {
     if ( defined( 'CIVICRM_DEBUG_LOG_QUERY' ) ) {
       if ( CIVICRM_DEBUG_LOG_QUERY == 'backtrace' ) {
-        CRM_Core_Error::backtrace( $string, true );
+        CRM_Core_Error::backtrace( $string, TRUE );
       } else if ( CIVICRM_DEBUG_LOG_QUERY ) {
-        CRM_Core_Error::debug_var( 'Query', $string, false, true );
+        CRM_Core_Error::debug_var( 'Query', $string, FALSE, TRUE );
       }
     }
   }
@@ -613,7 +622,7 @@ class CRM_Core_Error extends PEAR_ErrorStack {
     $dao = CRM_Core_DAO::executeQuery($query);
     $results = array();
     while ($dao->fetch()) {
-      $results[] = (array)$dao;
+      $results[] = (array) $dao;
     }
     CRM_Core_Error::debug_var('dao result', array('query' => $query, 'results' => $results));
   }
@@ -671,9 +680,12 @@ class CRM_Core_Error extends PEAR_ErrorStack {
   /**
    * Render a backtrace array as a string
    *
-   * @param array $backTrace array of stack frames
-   * @param boolean $showArgs TRUE if we should try to display content of function arguments (which could be sensitive); FALSE to display only the type of each function argument
-   * @param int $maxArgLen maximum number of characters to show from each argument string
+   * @param array $backTrace
+   *   Array of stack frames.
+   * @param bool $showArgs
+   *   TRUE if we should try to display content of function arguments (which could be sensitive); FALSE to display only the type of each function argument.
+   * @param int $maxArgLen
+   *   Maximum number of characters to show from each argument string.
    * @return string printable plain-text
    */
   public static function formatBacktrace($backTrace, $showArgs = TRUE, $maxArgLen = 80) {
@@ -681,16 +693,19 @@ class CRM_Core_Error extends PEAR_ErrorStack {
     foreach (self::parseBacktrace($backTrace, $showArgs, $maxArgLen) as $idx => $trace) {
       $message .= sprintf("#%s %s\n", $idx, $trace);
     }
-    $message .= sprintf("#%s {main}\n", 1+$idx);
+    $message .= sprintf("#%s {main}\n", 1 + $idx);
     return $message;
   }
 
   /**
    * Render a backtrace array as an array
    *
-   * @param array $backTrace array of stack frames
-   * @param boolean $showArgs TRUE if we should try to display content of function arguments (which could be sensitive); FALSE to display only the type of each function argument
-   * @param int $maxArgLen maximum number of characters to show from each argument string
+   * @param array $backTrace
+   *   Array of stack frames.
+   * @param bool $showArgs
+   *   TRUE if we should try to display content of function arguments (which could be sensitive); FALSE to display only the type of each function argument.
+   * @param int $maxArgLen
+   *   Maximum number of characters to show from each argument string.
    * @return array
    * @see debug_backtrace
    * @see Exception::getTrace()
@@ -715,25 +730,32 @@ class CRM_Core_Error extends PEAR_ErrorStack {
             case 'boolean':
               $args[] = $arg ? 'TRUE' : 'FALSE';
               break;
+
             case 'integer':
             case 'double':
               $args[] = $arg;
               break;
+
             case 'string':
               $args[] = '"' . CRM_Utils_String::ellipsify(addcslashes((string) $arg, "\r\n\t\""), $maxArgLen). '"';
               break;
+
             case 'array':
               $args[] = '(Array:'.count($arg).')';
               break;
+
             case 'object':
               $args[] = 'Object(' . get_class($arg) . ')';
               break;
+
             case 'resource':
               $args[] = 'Resource';
               break;
+
             case 'NULL':
               $args[] = 'NULL';
               break;
+
             default:
               $args[] = "($type)";
               break;
@@ -774,11 +796,11 @@ class CRM_Core_Error extends PEAR_ErrorStack {
           $msg .= '<tbody>';
           foreach (array('Type', 'Code', 'Message', 'Mode', 'UserInfo', 'DebugInfo') as $f) {
             $msg .= sprintf('<tr><td>%s</td><td>%s</td></tr>', $f, call_user_func(array($ei->getCause(), "get$f")));
-    }
+          }
           $msg .= '</tbody></table>';
-    }
+        }
         $ei = $ei->getCause();
-  }
+      }
       $msg .= $e->toHtml();
     } else {
       $msg .= '<p><b>' . get_class($e) . ': "' . htmlentities($e->getMessage()) . '"</b></p>';
@@ -826,7 +848,8 @@ class CRM_Core_Error extends PEAR_ErrorStack {
   /**
    * Set a status message in the session, then bounce back to the referrer.
    *
-   * @param string $status The status message to set
+   * @param string $status
+   *   The status message to set.
    *
    * @param null $redirect
    * @param string $title
@@ -873,7 +896,8 @@ class CRM_Core_Error extends PEAR_ErrorStack {
   /**
    * PEAR error-handler to quietly catch otherwise fatal errors. Intended for use with smtp transport.
    *
-   * @param object $obj       The PEAR_ERROR object
+   * @param object $obj
+   *   The PEAR_ERROR object.
    * @return object $obj
    * @static
    */