Skip to content

Commit

Permalink
Make codechecker work more reliably on Windows.
Browse files Browse the repository at this point in the history
  • Loading branch information
timhunt committed May 25, 2011
1 parent 22cef48 commit 3f364b8
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
6 changes: 3 additions & 3 deletions index.php
Expand Up @@ -49,7 +49,7 @@
$mform = new local_codechecker_form(new moodle_url('/local/codechecker/'));
$mform->set_data((object) array('path' => $path));
if ($data = $mform->get_data()) {
redirect('./?path=' . urlencode($data->path));
redirect(new moodle_url('/local/codechecker/', array('path' => $data->path)));
}

if ($path) {
Expand All @@ -68,8 +68,8 @@
$phpcs = new PHP_CodeSniffer();
$phpcs->setCli(new local_codechecker_codesniffer_cli());
$phpcs->setIgnorePatterns(local_codesniffer_get_ignores());
$phpcs->process($fullpath,
$CFG->dirroot . '/local/codechecker/moodle');
$phpcs->process(local_codechecker_clean_path($fullpath),
local_codechecker_clean_path($CFG->dirroot . '/local/codechecker/moodle'));
$problems = $phpcs->getFilesErrors();
ksort($problems);

Expand Down
19 changes: 16 additions & 3 deletions locallib.php
Expand Up @@ -91,10 +91,11 @@ function local_codesniffer_get_ignores() {

$thirdparty = simplexml_load_file($CFG->libdir . '/thirdpartylibs.xml');
foreach ($thirdparty->xpath('/libraries/library/location') as $lib) {
$paths[] = preg_quote('/lib/' . $lib);
$paths[] = preg_quote(local_codechecker_clean_path('/lib/' . $lib));
}

$paths[] = preg_quote('/local/codechecker' . DIRECTORY_SEPARATOR . 'pear');
$paths[] = preg_quote(local_codechecker_clean_path(
'/local/codechecker' . DIRECTORY_SEPARATOR . 'pear'));
return $paths;
}

Expand All @@ -110,4 +111,16 @@ function local_codechecker_get_line_of_code($line, $prettypath) {
}

return $file[$line - 1];
}
}

/**
* The code-checker code assumes that paths always use DIRECTORY_SEPARATOR,
* whereas Moodle is more relaxed than that. This method cleans up file paths by
* converting all / and \ to DIRECTORY_SEPARATOR. It should be used whenever a
* path is passed to the CodeSniffer library.
* @param string $path a file path
* @return the path with all directory separators changed to DIRECTORY_SEPARATOR.
*/
function local_codechecker_clean_path($path) {
return str_replace(array('\\', '/'), DIRECTORY_SEPARATOR, $path);
}
4 changes: 3 additions & 1 deletion run.php
Expand Up @@ -52,7 +52,9 @@
$phpcs = new PHP_CodeSniffer(1);
$phpcs->setCli(new local_codechecker_codesniffer_cli());
$phpcs->setIgnorePatterns(local_codesniffer_get_ignores());
$numerrors = $phpcs->process($CFG->dirroot . '/' . trim($path, '/'), $standard);
$numerrors = $phpcs->process(local_codechecker_clean_path(
$CFG->dirroot . '/' . trim($path, '/')),
local_codechecker_clean_path($standard));

$reporting = new PHP_CodeSniffer_Reporting();
$problems = $phpcs->getFilesErrors();
Expand Down

0 comments on commit 3f364b8

Please sign in to comment.