diff --git a/file.php b/file.php index 0d2e609..133094b 100644 --- a/file.php +++ b/file.php @@ -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 @@ -72,7 +71,6 @@ protected function clear_memory() { $this->allphpdocs = null; $this->variables = null; $this->defines = null; - $this->constants = null; } /** @@ -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 * diff --git a/lang/en/local_moodlecheck.php b/lang/en/local_moodlecheck.php index 82f93c1..d667d94 100644 --- a/lang/en/local_moodlecheck.php +++ b/lang/en/local_moodlecheck.php @@ -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 {$a->object} is not documented'; $string['rule_definesdocumented'] = 'All define statements are documented'; $string['error_definesdocumented'] = 'Define statement for {$a->object} is not documented'; diff --git a/rules/phpdocs_basic.php b/rules/phpdocs_basic.php index 76fceab..d6c751e 100644 --- a/rules/phpdocs_basic.php +++ b/rules/phpdocs_basic.php @@ -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'); @@ -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 * diff --git a/tests/moodlecheck_rules_test.php b/tests/moodlecheck_rules_test.php index 50ba0a1..b8c840b 100644 --- a/tests/moodlecheck_rules_test.php +++ b/tests/moodlecheck_rules_test.php @@ -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) *