Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove constsdocumented #140

Merged
merged 1 commit into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 0 additions & 43 deletions file.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ class local_moodlecheck_file {
protected $allphpdocs = null;
protected $variables = null;
protected $defines = null;
protected $constants = null;

/**
* Creates an object from path to the file
Expand All @@ -72,7 +71,6 @@ protected function clear_memory() {
$this->allphpdocs = null;
$this->variables = null;
$this->defines = null;
$this->constants = null;
}

/**
Expand Down Expand Up @@ -518,47 +516,6 @@ public function &get_variables() {
return $this->variables;
}

/**
* Returns all constants found in file
*
* Returns array of objects where each element represents a constant:
* $variable->tid : token id of the token with variable name
* $variable->name : name of the variable (starts with $)
* $variable->phpdocs : phpdocs for this variable (instance of local_moodlecheck_phpdocs or false if not found)
* $variable->class : containing class object
* $variable->fullname : name of the variable with class name (i.e. classname::$varname)
* $variable->boundaries : array with ids of first and last token for this constant
*
* @return array
*/
public function &get_constants() {
if ($this->constants === null) {
$this->constants = [];
$this->get_tokens();
for ($tid = 0; $tid < $this->tokenscount; $tid++) {
if ($this->tokens[$tid][0] == T_USE) {
// Skip the entire use statement, to avoid interpreting "use const" as a constant.
$tid = $this->end_of_statement($tid);
continue;
}

if ($this->tokens[$tid][0] == T_CONST && !$this->is_inside_function($tid)) {
$variable = new stdClass;
$variable->tid = $tid;
$variable->fullname = $variable->name = $this->next_nonspace_token($tid, false);
$variable->class = $this->is_inside_class($tid);
if ($variable->class !== false) {
$variable->fullname = $variable->class->name . '::' . $variable->name;
}
$variable->phpdocs = $this->find_preceeding_phpdoc($tid);
$variable->boundaries = $this->find_object_boundaries($variable);
$this->constants[] = $variable;
}
}
}
return $this->constants;
}

/**
* Returns all 'define' statements found in file
*
Expand Down
2 changes: 0 additions & 2 deletions lang/en/local_moodlecheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@

$string['error_emptynophpfile'] = 'The file is empty or doesn\'t contain PHP code. Skipped.';

$string['rule_constsdocumented'] = 'All constants are documented';
$string['error_constsdocumented'] = 'Constant <b>{$a->object}</b> is not documented';
$string['rule_definesdocumented'] = 'All define statements are documented';
$string['error_definesdocumented'] = 'Define statement for <b>{$a->object}</b> is not documented';

Expand Down
17 changes: 0 additions & 17 deletions rules/phpdocs_basic.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

defined('MOODLE_INTERNAL') || die;

local_moodlecheck_registry::add_rule('constsdocumented')->set_callback('local_moodlecheck_constsdocumented');
local_moodlecheck_registry::add_rule('definesdocumented')->set_callback('local_moodlecheck_definesdocumented');
local_moodlecheck_registry::add_rule('noinlinephpdocs')->set_callback('local_moodlecheck_noinlinephpdocs');
local_moodlecheck_registry::add_rule('phpdocsfistline')->set_callback('local_moodlecheck_phpdocsfistline');
Expand All @@ -35,22 +34,6 @@
local_moodlecheck_registry::add_rule('phpdocsuncurlyinlinetag')->set_callback('local_moodlecheck_phpdocsuncurlyinlinetag');
local_moodlecheck_registry::add_rule('phpdoccontentsinlinetag')->set_callback('local_moodlecheck_phpdoccontentsinlinetag');

/**
* Checks if all constants have phpdocs blocks
*
* @param local_moodlecheck_file $file
* @return array of found errors
*/
function local_moodlecheck_constsdocumented(local_moodlecheck_file $file) {
$errors = [];
foreach ($file->get_constants() as $object) {
if ($object->phpdocs === false) {
$errors[] = ['object' => $object->fullname, 'line' => $file->get_line_number($object->tid)];
}
}
return $errors;
}

/**
* Checks if all variables have phpdocs blocks
*
Expand Down
23 changes: 0 additions & 23 deletions tests/moodlecheck_rules_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -324,29 +324,6 @@ public function test_j_method_multiline(): void {
$this->assertSame(0, $found->length); // All examples in fixtures are ok.
}

/**
* Verify that "use function" statements are ignored.
*
* @covers ::local_moodlecheck_constsdocumented
*/
public function test_constsdocumented_ignore_uses(): void {
$file = __DIR__ . "/fixtures/uses.php";

global $PAGE;
$output = $PAGE->get_renderer('local_moodlecheck');
$path = new local_moodlecheck_path($file, null);
$result = $output->display_path($path, 'xml');

// Convert results to XML Object.
$xmlresult = new \DOMDocument();
$xmlresult->loadXML($result);

$xpath = new \DOMXpath($xmlresult);
$found = $xpath->query('//file/error[@source="constsdocumented"]');
// TODO: Change to DOMNodeList::count() when php71 support is gone.
$this->assertSame(0, $found->length);
}

/**
* Verify that the text format shown information about the severity of the problem (error vs warning)
*
Expand Down
Loading