You are here

function _coder_review_page_form_includes in Coder 7.2

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

Adds results to form definition for display on the coder review page.

Parameters

array $form: Form array definition to be modified, passed by reference.

array $coder_args: An array of Coder settings. See do_coder_reviews() for details.

string $name: Name of the form element.

array $files: An array of file objects to check and display the results for. See file_scan_directory() for details.

int $offset: An integer offset to munge filenames with.

array $exclusions: An array of exclusions that should be ignored in the $files array.

Return value

array Statistics array in form: string filename => array value of '#stats' from do_coder_reviews().

See also

do_coder_review()

file_scan_directory()

1 call to _coder_review_page_form_includes()
coder_review_page_form in coder_review/coder_review.module
Implements hook_form().

File

coder_review/coder_review.module, line 832
Developer module to assist with coder reviews and API upgrade suggestions.

Code

function _coder_review_page_form_includes(array &$form, array $coder_args, $name, array $files, $offset, $exclusions) {
  $stats = array();
  $coder_args['#name'] = $name;
  $weight = 0;
  $exclusions = str_replace(array(
    "\r\n",
    "\r",
    "\n",
    '/',
    '*',
    '.',
  ), array(
    '|',
    '|',
    '|',
    '\\/',
    '.*',
    '\\.',
  ), $exclusions);
  foreach ($files as $file) {
    if (!empty($exclusions) && preg_match("/{$exclusions}/", $file)) {

      // Don't review this file.
      continue;
    }
    $filename = _substr($file, $offset);
    $php_extensions = _coder_review_php_ext();
    $coder_args['#filename'] = $filename;
    $coder_args['#php_extensions'] = $php_extensions;
    $results = do_coder_reviews($coder_args);
    $stats[$filename] = $results['#stats'];
    unset($results['#stats']);
    if (function_exists('module_invoke_all')) {
      module_invoke_all('coder_review_results_view', $results);
    }

    // Output the results in a collapsible fieldset.
    $form[$name][$filename] = array(
      '#type' => 'fieldset',
      '#title' => $filename,
      '#collapsible' => TRUE,
      '#collapsed' => TRUE,
      '#weight' => ++$weight,
    );
    if ($results) {
      $form[$name][$filename]['#collapsed'] = FALSE;
      $form[$name]['#collapsed'] = FALSE;
    }
    else {
      $results[] = _t('No Problems Found');
    }
    if (_drush()) {
      theme_drush_coder_review(array(
        'name' => $name,
        'filename' => $filename,
        'results' => $results,
      ));
    }
    else {
      $form[$name][$filename]['output'] = array(
        '#theme' => 'coder_review',
        '#name' => $name,
        '#filename' => $filename,
        '#results' => $results,
      );
    }
  }
  return $stats;
}