You are here

function _coder_review_warning in Coder 7.2

Same name and namespace in other branches
  1. 7 coder_review/coder_review.module \_coder_review_warning()

Creates a formatted warning message from a Rule array definition.

Parameters

array $rule: A Rule definition array.

Return value

string A formatted warning message. @todo Is this an HTML string? Is it sanitized? Needs better explanation.

1 call to _coder_review_warning()
do_coder_reviews in coder_review/coder_review.common.inc
Performs coder reviews for multiple code review definition files.

File

coder_review/coder_review.common.inc, line 1391
Common functions used by both the drush and form interfaces.

Code

function _coder_review_warning(array $rule) {

  /* @todo: add version check so we handle tranlations right for older rules definitions.
   * ... or should we just ignore them?
   * This will require passing the review to this function.
   */

  // Call warning callbacks.
  if (isset($rule['#warning_callback'])) {

    // This rule definition is deprecated.
    if (is_callable($rule['#warning_callback']) || function_exists($rule['#warning_callback'])) {
      return $rule['#warning_callback']();
    }
  }
  elseif (isset($rule['#warning'])) {

    // Return array warnings as-is.
    // They get translated in theme_coder_review_warning().
    if (is_array($rule['#warning'])) {
      return $rule['#warning'];
    }

    // Warnings callback functions can now be stored as the #warning element.
    if (is_callable($rule['#warning']) || function_exists($rule['#warning'])) {
      return $rule['#warning']();
    }

    // Translate the warning message and return it.
    return _t($rule['#warning']);
  }

  // No valid warning definition: return a warning about the warning.
  return _t('Unknown warning');
}