if ($path) {
    $fullpath = $CFG->dirroot . '/' . trim($path, '/');
    if (!is_file($fullpath) && !is_dir($fullpath)) {
        $fullpath = null;
    }
}
$output = $PAGE->get_renderer('local_codechecker');
echo $OUTPUT->header();
if ($path) {
    if ($fullpath) {
        $phpcs = new PHP_CodeSniffer();
        $phpcs->setCli(new local_codechecker_codesniffer_cli());
        $phpcs->setIgnorePatterns(local_codesniffer_get_ignores());
        $phpcs->process(local_codechecker_clean_path($fullpath), local_codechecker_clean_path($CFG->dirroot . '/local/codechecker/moodle'));
        $problems = $phpcs->getFilesErrors();
        local_codechecker_check_other_files(local_codechecker_clean_path($fullpath), $problems);
        ksort($problems);
        $errors = 0;
        $warnings = 0;
        foreach ($problems as $file => $info) {
            $errors += $info['numErrors'];
            $warnings += $info['numWarnings'];
        }
        if ($errors + $warnings > 0) {
            $summary = get_string('numerrorswarnings', 'local_codechecker', array('numErrors' => $errors, 'numWarnings' => $warnings));
        } else {
            $summary = '';
        }
        echo $output->report($problems, $phpcs, $summary);
    } else {
        echo $output->invald_path_message($path);
$output = $PAGE->get_renderer('local_codechecker');
echo $OUTPUT->header();
if ($path) {
    if ($fullpath) {
        $reportfile = make_temp_directory('phpcs') . '/phpcs_' . random_string(10) . '.xml';
        $phpcs = new PHP_CodeSniffer();
        $cli = new local_codechecker_codesniffer_cli();
        $cli->setReport('local_codechecker');
        // Using own custom xml format for easier handling later.
        $cli->setReportFile($reportfile);
        // Send the report to dataroot temp.
        $phpcs->setCli($cli);
        $phpcs->setIgnorePatterns(local_codesniffer_get_ignores($exclude));
        $phpcs->process(local_codechecker_clean_path($fullpath), local_codechecker_clean_path($CFG->dirroot . '/local/codechecker/moodle'));
        // Save the xml report file to dataroot/temp.
        $phpcs->reporting->printReport('local_codechecker', false, $reportfile);
        // Load the XML file to proceed with the rest of checks.
        $xml = simplexml_load_file($reportfile);
        // Look for other problems, not handled by codesniffer.
        local_codechecker_check_other_files(local_codechecker_clean_path($fullpath), $xml);
        list($numerrors, $numwarnings) = local_codechecker_count_problems($xml);
        // Output the results report.
        echo $output->report($xml, $numerrors, $numwarnings);
        // And clean the report temp file.
        @unlink($reportfile);
    } else {
        echo $output->invald_path_message($path);
    }
}
$mform->display();
echo $OUTPUT->footer();