/**
 * 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;
}
/**
 * Makes sure that files have license tag
 *
 * @param local_moodlecheck_file $file
 * @return array of found errors
 */
function local_moodlecheck_filehaslicense(local_moodlecheck_file $file)
{
    $phpdocs = $file->find_file_phpdocs();
    if ($phpdocs && !count($phpdocs->get_tags('license', true))) {
        return array(array('line' => $phpdocs->get_line_number($file, '@license')));
    }
    return array();
}