/** * Generates html to display one path validation results (invoked recursively) * * @param local_moodlecheck_path $path * @param string $format display format: html, xml, text * @return string */ public function display_path(local_moodlecheck_path $path, $format = 'html') { $output = ''; $path->validate(); if ($path->is_dir()) { if ($format == 'html') { $output .= html_writer::start_tag('li', array('class' => 'directory')); $output .= html_writer::tag('span', $path->get_path(), array('class' => 'dirname')); $output .= html_writer::start_tag('ul', array('class' => 'directory')); } else { if ($format == 'xml' && $path->is_rootpath()) { // Insert XML preamble and root element $output .= '<?xml version="1.0" encoding="UTF-8"?>' . PHP_EOL . '<checkstyle version="1.3.2">' . PHP_EOL; } } foreach ($path->get_subpaths() as $subpath) { $output .= $this->display_path($subpath, $format); } if ($format == 'html') { $output .= html_writer::end_tag('li'); $output .= html_writer::end_tag('ul'); } else { if ($format == 'xml' && $path->is_rootpath()) { // Close root element $output .= '</checkstyle>'; } } } else { if ($path->is_file() && $path->get_file()->needs_validation()) { $output .= $this->display_file_validation($path->get_path(), $path->get_file(), $format); } } return $output; }
public function validate() { if ($this->validated) { // prevent from second validation return; } if (is_file($this->get_fullpath())) { $this->file = new local_moodlecheck_file($this->get_fullpath()); } else { if (is_dir($this->get_fullpath())) { $this->subpaths = array(); if ($dh = opendir($this->get_fullpath())) { while (($file = readdir($dh)) !== false) { if ($file != '.' && $file != '..' && $file != '.git' && !$this->is_ignored($file)) { $subpath = new local_moodlecheck_path($this->path . '/' . $file, $this->ignorepaths); $subpath->set_rootpath(false); $this->subpaths[] = $subpath; } } closedir($dh); } } } $this->validated = true; }