function coder_page_form in Coder 6.2
Same name and namespace in other branches
- 5.2 coder.module \coder_page_form()
- 5 coder.module \coder_page_form()
- 6 coder.module \coder_page_form()
Implementation of hook_form().
Implements coder's main form, in which a user can select reviews and modules/themes to run them on.
1 call to coder_page_form()
1 string reference to 'coder_page_form'
- coder_page in ./
coder.module - Implementation of code review page.
File
- ./
coder.module, line 696
Code
function coder_page_form($form_state) {
if (isset($form_state['storage'])) {
$settings = $form_state['storage'];
$settings['coder_modules'] = _coder_settings_array($form_state, 'module');
$settings['coder_themes'] = _coder_settings_array($form_state, 'theme');
drupal_set_title(t('Code review (submitted options)'));
}
else {
$arg = arg(1);
$settings = _coder_get_default_settings($arg);
if ($arg) {
drupal_set_title(t('Code review (@options)', array(
'@options' => isset($arg) ? $arg : 'default options',
)));
}
}
// Get this once: list of the reviews to perform.
$reviews = array();
$avail_reviews = _coder_reviews();
$selected_reviews = $settings['coder_reviews'];
foreach ($selected_reviews as $name => $checked) {
if ($checked) {
$reviews[$name] = $avail_reviews[$name];
}
}
if ($coder_form = _coder_settings_form($settings, $system, $files)) {
// Add style sheet.
$path = drupal_get_path('module', 'coder');
drupal_add_css($path . '/coder.css', 'module');
// Get the includes_exclusions settings once, it is used multiple times.
$coder_includes_exclusions = isset($settings['coder_includes_exclusions']) ? $settings['coder_includes_exclusions'] : '';
// Get the list of lines to ignore.
$ignores = coder_get_ignores();
// Code review non-module core files.
$module_weight = 0;
if (isset($settings['coder_core']) && $settings['coder_core']) {
$coder_args = array(
'#reviews' => $reviews,
'#severity' => $settings['coder_severity'],
'#include_extensions' => array(),
);
$form['core_php'] = array(
'#type' => 'fieldset',
'#title' => 'core (php)',
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#weight' => ++$module_weight,
);
$phpfiles = file_scan_directory('.', '.*\\.php', array(
'.',
'..',
'CVS',
'.svn',
'.git',
), 0, FALSE, 'name', 0);
_coder_page_form_includes($form, $coder_args, 'core_php', $phpfiles, 2, $coder_includes_exclusions, $ignores);
$form['core_includes'] = array(
'#type' => 'fieldset',
'#title' => 'core (includes)',
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#weight' => ++$module_weight,
);
$includefiles = drupal_system_listing('.*\\.inc$', 'includes', 'filename', 0);
_coder_page_form_includes($form, $coder_args, 'core_includes', $includefiles, 0, $coder_includes_exclusions, $ignores);
}
// Loop through the selected modules and themes.
if (isset($system)) {
// Determine which file extensions to include, based on the rules.
$php_extensions = variable_get('coder_php_ext', array(
'inc',
'php',
'install',
'test',
));
$include_extensions = _coder_get_reviews_extensions($php_extensions, $reviews);
$includes = array_merge($php_extensions, $include_extensions);
// Used to avoid duplicate includes.
$dups = array();
$stats = array();
$patch = '';
foreach ($system as $name => $checked) {
if ($checked) {
// Process this one file.
$filename = $files[$name];
if (!$filename) {
drupal_set_message(t('Code Review file for %module not found', array(
'%module' => $name,
)), 'error');
continue;
}
if (!empty($settings['coder_patches'])) {
$patch = $filename;
$filename = $name;
}
$coder_args = array(
'#reviews' => $reviews,
'#severity' => $settings['coder_severity'],
'#filename' => $filename,
'#patch' => $patch,
'#php_extensions' => $php_extensions,
'#include_extensions' => $include_extensions,
'#ignore_lines' => isset($ignores[$filename]) && is_array($ignores[$filename]) ? $ignores[$filename] : array(),
'#cache' => TRUE,
);
drupal_alter('coder_review_args', $coder_args);
$results = do_coder_reviews($coder_args);
$stats[$filename] = $results['#stats'];
unset($results['#stats']);
module_invoke_all('coder_results_view', $results);
// Output the results in a collapsible fieldset.
$form[$name] = array(
'#type' => 'fieldset',
'#title' => $filename,
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#weight' => ++$module_weight,
);
if (empty($results)) {
$results[] = t('No Problems Found');
}
else {
$form[$name]['#collapsed'] = FALSE;
}
$form[$name]['output'] = array(
'#value' => theme('coder', $name, $filename, $results),
'#weight' => -1,
);
// Process the same directory include files.
if (!empty($settings['coder_includes'])) {
// NOTE: Convert to the realpath here so drupal_system_listing
// doesn't return additional paths (i.e., try "module").
if ($path = str_replace('\\', '/', dirname(realpath($filename)))) {
if (!isset($dups[$path])) {
if (drupal_substr($filename, -7) == '.module') {
$coder_args['#php_minor'] = 1;
}
$dups[$path] = 1;
$regex = '\\.(' . implode('|', $includes) . ')$';
$includefiles = drupal_system_listing($regex, dirname($filename), 'filename', 0);
$offset = strpos($filename, dirname($filename));
$stats[$filename]['#includes'] = _coder_page_form_includes($form, $coder_args, $name, $includefiles, $offset, $coder_includes_exclusions, $ignores);
}
}
}
}
}
if (count($stats)) {
$summary = array(
'files' => 0,
'minor' => 0,
'normal' => 0,
'critical' => 0,
'ignored' => 0,
);
foreach ($stats as $stat) {
$summary['minor'] += $stat['minor'];
$summary['normal'] += $stat['normal'];
$summary['critical'] += $stat['critical'];
$summary['ignored'] += $stat['ignored'];
if (isset($stat['#includes'])) {
foreach ($stat['#includes'] as $includestat) {
$summary['files']++;
$summary['minor'] += $includestat['minor'];
$summary['normal'] += $includestat['normal'];
$summary['critical'] += $includestat['critical'];
$summary['ignored'] += $includestat['ignored'];
}
}
$summary['files']++;
}
$display = array();
if (empty($settings['coder_patches'])) {
$display[] = t('Coder found @count projects', array(
'@count' => count($stats),
));
$display[] = t('@count files', array(
'@count' => $summary['files'],
));
}
else {
$display[] = t('Coder found @count patch hunks', array(
'@count' => count($stats),
));
}
foreach (array(
'critical',
'normal',
'minor',
) as $severity_name) {
if ($summary[$severity_name] > 0) {
$display[] = t('@count %severity_name warnings', array(
'@count' => $summary[$severity_name],
'%severity_name' => $severity_name,
));
}
}
$display[] = t('@count warnings were flagged to be ignored', array(
'@count' => $summary['ignored'],
));
drupal_set_message(implode(', ', $display));
if (function_exists('_coder_drush_is_option') && _coder_drush_is_option('drush')) {
print coder_print_drush_messages();
}
}
}
// Prepend the settings form.
$form['settings'] = array(
'#type' => 'fieldset',
'#title' => t('Selection form'),
'#collapsible' => TRUE,
'#collapsed' => isset($form),
'#weight' => -1,
);
if ($form['settings']['#collapsed']) {
$form['settings']['#prefix'] = t('<div class="coder-settings">Use the Selection form to select options for this code review, or change the <a href="@settings">Default Settings</a> and use the <a href="@default">Default</a> tab above.</div>', array(
'@settings' => url('admin/settings/coder'),
'@default' => url('coder/default'),
));
}
$form['settings'][] = $coder_form;
$form['settings']['submit'] = array(
'#type' => 'submit',
'#value' => t('Submit'),
);
}
return $form;
}