Ejemplo n.º 1
0
 /**
  * Generates html to display one file validation results
  *
  * @param string $filename
  * @param local_moodlecheck_file $file
  * @param string $format display format: html, xml, text
  * @return string
  */
 public function display_file_validation($filename, local_moodlecheck_file $file, $format = 'html')
 {
     $output = '';
     $errors = $file->validate();
     if ($format == 'html') {
         $output .= html_writer::start_tag('li', array('class' => 'file'));
         $output .= html_writer::tag('span', $filename, array('class' => 'filename'));
         $output .= html_writer::start_tag('ul', array('class' => 'file'));
     } else {
         if ($format == 'xml') {
             $output .= html_writer::start_tag('file', array('name' => $filename)) . "\n";
         } else {
             if ($format == 'text') {
                 $output .= $filename . "\n";
             }
         }
     }
     foreach ($errors as $error) {
         if (($format == 'html' || $format == 'text') && isset($error['line']) && strlen($error['line'])) {
             $error['message'] = get_string('linenum', 'local_moodlecheck', $error['line']) . $error['message'];
         }
         if ($format == 'html') {
             $output .= html_writer::tag('li', $error['message'], array('class' => 'errorline'));
         } else {
             $error['message'] = strip_tags($error['message']);
             if ($format == 'text') {
                 $output .= "    " . $error['message'] . "\n";
             } else {
                 if ($format == 'xml') {
                     $output .= '  ' . html_writer::empty_tag('error', $error) . "\n";
                 }
             }
         }
     }
     if ($format == 'html') {
         $output .= html_writer::end_tag('ul');
         $output .= html_writer::end_tag('li');
     } else {
         if ($format == 'xml') {
             $output .= html_writer::end_tag('file') . "\n";
         }
     }
     return $output;
 }
/**
 * Makes sure that all classes have license tag
 *
 * @param local_moodlecheck_file $file
 * @return array of found errors
 */
function local_moodlecheck_classeshavelicense(local_moodlecheck_file $file)
{
    $errors = array();
    foreach ($file->get_classes() as $class) {
        if ($class->phpdocs && !count($class->phpdocs->get_tags('license', true))) {
            $errors[] = array('line' => $class->phpdocs->get_line_number($file, '@license'), 'object' => $class->name);
        }
    }
    return $errors;
}
/**
 * Returns package names available for the file location
 * 
 * If the file is inside plugin directory only frankenstyle name for this plugin is returned
 * Otherwise returns list of available core packages
 *
 * @param local_moodlecheck_file $file
 * @return array
 */
function local_moodlecheck_package_names(local_moodlecheck_file $file)
{
    // Check if $file is inside any plugin directory
    foreach (local_moodlecheck_get_plugins() as $pluginfullname => $dir) {
        if ($file->is_in_dir($dir)) {
            return array($pluginfullname);
        }
    }
    // If not return list of core packages
    static $corepackages = array();
    if (empty($corepackages)) {
        $coresubsystems = get_core_subsystems();
        foreach ($coresubsystems as $key => $val) {
            $corepackages[] = 'core_' . $key;
        }
    }
    return $corepackages;
}
Ejemplo n.º 4
0
 /**
  * Returns the line number where this phpdoc occurs in the file
  *
  * @param local_moodlecheck_file $file
  * @param string $substring if specified the line number of first occurence of $substring is returned
  * @return int
  */
 public function get_line_number(local_moodlecheck_file $file, $substring = null)
 {
     $line0 = $file->get_line_number($this->get_original_token_id());
     if ($substring === null) {
         return $line0;
     } else {
         $chunks = split($substring, $this->originaltoken[1]);
         if (count($chunks) > 1) {
             $lines = split("\n", $chunks[0]);
             return $line0 + count($lines) - 1;
         } else {
             return $line0;
         }
     }
 }