Skip to content

Commit

Permalink
Remove package checks.
Browse files Browse the repository at this point in the history
These are now processed by moodle-cs.
  • Loading branch information
andrewnicols committed Feb 19, 2024
1 parent 01c8320 commit 036d54a
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 314 deletions.
6 changes: 0 additions & 6 deletions lang/en/local_moodlecheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,6 @@
$string['error_definedoccorrect'] = 'Phpdocs for define statement must start with constant name and dash: <b>{$a->object}</b>';
$string['rule_definedoccorrect'] = 'Check syntax for define statement';

$string['error_packagespecified'] = 'Package is not specified for <b>{$a->object}</b>. It is also not specified in file-level phpdocs';
$string['rule_packagespecified'] = 'All functions (which are not methods) and classes have package specified or inherited';

$string['rule_packagevalid'] = 'Package tag is valid';
$string['error_packagevalid'] = 'Package <b>{$a->package}</b> is not valid';

$string['rule_categoryvalid'] = 'Category tag is valid';
$string['error_categoryvalid'] = 'Category <b>{$a->category}</b> is not valid';

Expand Down
143 changes: 0 additions & 143 deletions rules/phpdocs_package.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,68 +24,8 @@

defined('MOODLE_INTERNAL') || die;

local_moodlecheck_registry::add_rule('packagespecified')->set_callback('local_moodlecheck_packagespecified');
local_moodlecheck_registry::add_rule('packagevalid')->set_callback('local_moodlecheck_packagevalid');
local_moodlecheck_registry::add_rule('categoryvalid')->set_callback('local_moodlecheck_categoryvalid');

/**
* 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 = [];
$phpdocs = $file->find_file_phpdocs();
if ($phpdocs && count($phpdocs->get_tags('package', true))) {
// Package is specified on file level, it is automatically inherited.
return [];
}

foreach ($file->get_artifacts_flat() as $artifact) {
if (!$artifact->phpdocs || !count($artifact->phpdocs->get_tags('package', true))) {
$errors[] = [
'line' => $file->get_line_number($artifact->boundaries[0]),
'object' => "$artifact->typestring $artifact->name",
];
}
}

foreach ($file->get_functions() as $object) {
if ($object->owner === false) {
if (!$object->phpdocs || !count($object->phpdocs->get_tags('package', true))) {
$errors[] = [
'line' => $file->get_line_number($object->boundaries[0]),
'object' => 'function ' . $object->fullname,
];
}
}
}
return $errors;
}

/**
* Checks that wherever the package token is specified it is valid
*
* @param local_moodlecheck_file $file
* @return array of found errors
*/
function local_moodlecheck_packagevalid(local_moodlecheck_file $file) {
$errors = [];

$allowedpackages = local_moodlecheck_package_names($file);
foreach ($file->get_all_phpdocs() as $phpdoc) {
foreach ($phpdoc->get_tags('package') as $package) {
if (!in_array($package, $allowedpackages)) {
$errors[] = ['line' => $phpdoc->get_line_number($file, '@package'), 'package' => $package];
}
}
}
return $errors;
}

/**
* Checks that wherever the category token is specified it is valid
*
Expand All @@ -105,89 +45,6 @@ function local_moodlecheck_categoryvalid(local_moodlecheck_file $file) {
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) {
static $allplugins = [];
static $allsubsystems = [];
static $corepackages = [];
// Get and cache the list of plugins.
if (empty($allplugins)) {
$components = local_moodlecheck_path::get_components();
// First try to get the list from file components.
if (isset($components['plugin'])) {
$allplugins = $components['plugin'];
} else {
$allplugins = local_moodlecheck_get_plugins();
}
}
// Get and cache the list of subsystems.
if (empty($allsubsystems)) {
$components = local_moodlecheck_path::get_components();
// First try to get the list from file components.
if (isset($components['subsystem'])) {
$allsubsystems = $components['subsystem'];
} else {
$allsubsystems = get_core_subsystems(true);
}
// Prepare the list of core packages.
foreach ($allsubsystems as $subsystem => $dir) {
// Subsytems may come with the valid component name (core_ prefixed) already.
if (strpos($subsystem, 'core_') === 0 || $subsystem === 'core') {
$corepackages[] = $subsystem;
} else {
$corepackages[] = 'core_' . $subsystem;
}
}
// Add "core" if missing.
if (!in_array('core', $corepackages)) {
$corepackages[] = 'core';
}
}

// Return valid plugin if the $file belongs to it.
foreach ($allplugins as $pluginfullname => $dir) {
if ($file->is_in_dir($dir)) {
return [$pluginfullname];
}
}

// If not return list of valid core packages.
return $corepackages;
}

/**
* Returns all installed plugins
*
* Returns all installed plugins as an associative array
* with frankenstyle name as a key and plugin directory as a value
*
* @return array
*/
function &local_moodlecheck_get_plugins() {
static $allplugins = [];
if (empty($allplugins)) {
$plugintypes = get_plugin_types();
foreach ($plugintypes as $plugintype => $pluginbasedir) {
if ($plugins = get_plugin_list($plugintype)) {
foreach ($plugins as $plugin => $plugindir) {
$allplugins[$plugintype.'_'.$plugin] = $plugindir;
}
}
}
asort($allplugins);
$allplugins = array_reverse($allplugins, true);
}
return $allplugins;
}

/**
* Reads the list of Core APIs from internet (or local copy) and returns the list of categories
*
Expand Down
118 changes: 0 additions & 118 deletions tests/fixtures/phpdoc_tags_packagespecified.php

This file was deleted.

Loading

0 comments on commit 036d54a

Please sign in to comment.