/**
 * Checks if all functions (outside class) and classes have package
 * 
 * package tag may be inherited from file-level phpdocs
 *
 * @param local_moodlecheck_file $file
 * @return array of found errors
 */
function local_moodlecheck_packagespecified(local_moodlecheck_file $file)
{
    $errors = array();
    $phpdocs = $file->find_file_phpdocs();
    if ($phpdocs && count($phpdocs->get_tags('package', true))) {
        // package is specified on file level, it is automatically inherited
        return array();
    }
    foreach ($file->get_classes() as $object) {
        if (!$object->phpdocs || !count($object->phpdocs->get_tags('package', true))) {
            $errors[] = array('line' => $file->get_line_number($object->boundaries[0]), 'object' => 'class ' . $object->name);
        }
    }
    foreach ($file->get_functions() as $object) {
        if ($object->class === false) {
            if (!$object->phpdocs || !count($object->phpdocs->get_tags('package', true))) {
                $errors[] = array('line' => $file->get_line_number($object->boundaries[0]), 'object' => 'function ' . $object->fullname);
            }
        }
    }
    return $errors;
}
/**
 * Checks if all variables have phpdocs blocks
 *
 * @param local_moodlecheck_file $file
 * @return array of found errors
 */
function local_moodlecheck_definesdocumented(local_moodlecheck_file $file)
{
    $errors = array();
    foreach ($file->get_defines() as $object) {
        if ($object->phpdocs === false) {
            $errors[] = array('object' => $object->fullname, 'line' => $file->get_line_number($object->tid));
        }
    }
    return $errors;
}
Exemplo n.º 3
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;
         }
     }
 }