Skip to content

Commit

Permalink
Remove constsdocumented (#140)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewnicols committed Mar 22, 2024
1 parent 2c7f500 commit ac44b0d
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 83 deletions.
41 changes: 0 additions & 41 deletions file.php
Original file line number Diff line number Diff line change
Expand Up @@ -518,47 +518,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

0 comments on commit ac44b0d

Please sign in to comment.