From 7bffe4dda557ea56bf59350bcf1ac222f54489dd Mon Sep 17 00:00:00 2001 From: Andrew Lyons Date: Wed, 20 Mar 2024 06:25:49 +0800 Subject: [PATCH] Remove variablesdocumented (#135) Replaced by https://github.com/moodlehq/moodle-cs/pull/121 Co-authored-by: Eloy Lafuente --- lang/en/local_moodlecheck.php | 5 --- rules/phpdocs_basic.php | 39 ------------------- tests/fixtures/phpdoc_properties.php | 56 ---------------------------- tests/moodlecheck_rules_test.php | 43 --------------------- 4 files changed, 143 deletions(-) delete mode 100644 tests/fixtures/phpdoc_properties.php diff --git a/lang/en/local_moodlecheck.php b/lang/en/local_moodlecheck.php index bed9bb3..82f93c1 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_variablesdocumented'] = 'All variables are documented'; -$string['error_variablesdocumented'] = 'Variable {$a->variable} is not documented'; $string['rule_constsdocumented'] = 'All constants are documented'; $string['error_constsdocumented'] = 'Constant {$a->object} is not documented'; $string['rule_definesdocumented'] = 'All define statements are documented'; @@ -65,9 +63,6 @@ $string['error_functionarguments'] = 'Phpdocs for function {$a->function} has incomplete parameters list'; $string['rule_functionarguments'] = 'Phpdocs for functions properly define all parameters'; -$string['error_variableshasvar'] = 'Phpdocs for variable {$a->variable} does not contain @var or incorrect'; -$string['rule_variableshasvar'] = 'Phpdocs for variables contain @var with variable type and name'; - $string['error_definedoccorrect'] = 'Phpdocs for define statement must start with constant name and dash: {$a->object}'; $string['rule_definedoccorrect'] = 'Check syntax for define statement'; diff --git a/rules/phpdocs_basic.php b/rules/phpdocs_basic.php index 05a42ea..76fceab 100644 --- a/rules/phpdocs_basic.php +++ b/rules/phpdocs_basic.php @@ -24,35 +24,17 @@ defined('MOODLE_INTERNAL') || die; -local_moodlecheck_registry::add_rule('variablesdocumented')->set_callback('local_moodlecheck_variablesdocumented'); 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'); local_moodlecheck_registry::add_rule('functiondescription')->set_callback('local_moodlecheck_functiondescription'); local_moodlecheck_registry::add_rule('functionarguments')->set_callback('local_moodlecheck_functionarguments'); -local_moodlecheck_registry::add_rule('variableshasvar')->set_callback('local_moodlecheck_variableshasvar'); local_moodlecheck_registry::add_rule('definedoccorrect')->set_callback('local_moodlecheck_definedoccorrect'); local_moodlecheck_registry::add_rule('phpdocsinvalidinlinetag')->set_callback('local_moodlecheck_phpdocsinvalidinlinetag'); 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 variables have phpdocs blocks - * - * @param local_moodlecheck_file $file - * @return array of found errors - */ -function local_moodlecheck_variablesdocumented(local_moodlecheck_file $file) { - $errors = []; - foreach ($file->get_variables() as $variable) { - if ($variable->phpdocs === false) { - $errors[] = ['variable' => $variable->fullname, 'line' => $file->get_line_number($variable->tid)]; - } - } - return $errors; -} - /** * Checks if all constants have phpdocs blocks * @@ -340,27 +322,6 @@ function($type) { return implode('|', $types); } -/** - * Checks that all variables have proper \var token in phpdoc block - * - * @param local_moodlecheck_file $file - * @return array of found errors - */ -function local_moodlecheck_variableshasvar(local_moodlecheck_file $file) { - $errors = []; - foreach ($file->get_variables() as $variable) { - if ($variable->phpdocs !== false) { - $documentedvars = $variable->phpdocs->get_params('var', 2); - if (!count($documentedvars) || $documentedvars[0][0] == 'type') { - $errors[] = [ - 'line' => $variable->phpdocs->get_line_number($file, '@var'), - 'variable' => $variable->fullname, ]; - } - } - } - return $errors; -} - /** * Checks that all define statement have constant name in phpdoc block * diff --git a/tests/fixtures/phpdoc_properties.php b/tests/fixtures/phpdoc_properties.php deleted file mode 100644 index 8b3cb02..0000000 --- a/tests/fixtures/phpdoc_properties.php +++ /dev/null @@ -1,56 +0,0 @@ -. - -defined('MOODLE_INTERNAL') || die(); - -/** - * A dummy class for tests of rules involving properties. - */ -class dummy_with_properties { - var $undocumented1; - var ?string $undocumented2; - private $undocumented3; - private ?string $undocumented4; - const UNDOCUMENTED_CONSTANT1 = 0; - public const UNDOCUMENTED_CONSTANT2 = 0; - - /** - * @const A wrongly documented constant. - */ - const WRONGLY_DOCUMENTED_CONSTANT = 0; - - /** - * @var mixed $documented1 I'm just a dummy! - */ - var $documented1; - /** - * @var mixed $documented2 I'm just a dummy! - */ - var ?string $documented2; - /** - * @var mixed $documented3 I'm just a dummy! - */ - private $documented3; - /** - * @var ?string $documented4 I'm just a dummy! - */ - private ?string $documented4; - - /** - * @var A correctly documented constant. - */ - const CORRECTLY_DOCUMENTED_CONSTANT = 0; -} diff --git a/tests/moodlecheck_rules_test.php b/tests/moodlecheck_rules_test.php index c7fffbc..50ba0a1 100644 --- a/tests/moodlecheck_rules_test.php +++ b/tests/moodlecheck_rules_test.php @@ -347,49 +347,6 @@ public function test_constsdocumented_ignore_uses(): void { $this->assertSame(0, $found->length); } - /** - * Verify that `variablesdocumented` correctly detects PHPdoc on different kinds of properties. - * - * @covers ::local_moodlecheck_variablesdocumented - * @covers \local_moodlecheck_file::get_variables - */ - public function test_variables_and_constants_documented(): void { - $file = __DIR__ . "/fixtures/phpdoc_properties.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); - - // Verify that the undocumented variables are reported. - - $found = $xpath->query('//file/error[@source="variablesdocumented"]'); - // TODO: Change to DOMNodeList::count() when php71 support is gone. - $this->assertSame(4, $found->length); - - // The PHPdocs of the other properties should be detected correctly. - $this->assertStringContainsString('$undocumented1', $found->item(0)->getAttribute("message")); - $this->assertStringContainsString('$undocumented2', $found->item(1)->getAttribute("message")); - $this->assertStringContainsString('$undocumented3', $found->item(2)->getAttribute("message")); - $this->assertStringContainsString('$undocumented4', $found->item(3)->getAttribute("message")); - - // Verify that the undocumented constants are reported. - - $found = $xpath->query('//file/error[@source="constsdocumented"]'); - // TODO: Change to DOMNodeList::count() when php71 support is gone. - $this->assertSame(2, $found->length); - - // The PHPdocs of the other properties should be detected correctly. - $this->assertStringContainsString('UNDOCUMENTED_CONSTANT1', $found->item(0)->getAttribute("message")); - $this->assertStringContainsString('UNDOCUMENTED_CONSTANT2', $found->item(1)->getAttribute("message")); - } - /** * Verify that the text format shown information about the severity of the problem (error vs warning) *