From a906ece978d54ae9ebb2257bcade0a9bc9f38057 Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Sat, 23 Mar 2024 14:10:11 +0800 Subject: [PATCH] Remove phpdocsfistline and functiondescription (#142) Replaced by https://github.com/moodlehq/moodle-cs/pull/134 --- file.php | 14 ----------- lang/en/local_moodlecheck.php | 6 ----- rules/phpdocs_basic.php | 47 ----------------------------------- 3 files changed, 67 deletions(-) diff --git a/file.php b/file.php index 133094b..0541897 100644 --- a/file.php +++ b/file.php @@ -1267,20 +1267,6 @@ public function get_original_token_id() { return $this->originaltid; } - /** - * Returns short description found in phpdocs if found (first line followed by empty line) - * - * @return string - */ - public function get_shortdescription() { - $lines = preg_split('/\n/', $this->description); - if (count($lines) == 1 || (count($lines) && !strlen(trim($lines[1])))) { - return $lines[0]; - } else { - return false; - } - } - /** * Returns list of parsed param tokens found in phpdocs * diff --git a/lang/en/local_moodlecheck.php b/lang/en/local_moodlecheck.php index d667d94..79b07ff 100644 --- a/lang/en/local_moodlecheck.php +++ b/lang/en/local_moodlecheck.php @@ -43,9 +43,6 @@ $string['rule_noinlinephpdocs'] = 'There are no comments starting with three or more slashes'; $string['error_noinlinephpdocs'] = 'Found comment starting with three or more slashes'; -$string['error_phpdocsfistline'] = 'No one-line description found in phpdocs for {$a->object}'; -$string['rule_phpdocsfistline'] = 'File-level phpdocs block and class phpdocs should have one-line short description'; - $string['error_phpdocsinvalidinlinetag'] = 'Invalid inline phpdocs tag {$a->tag} found'; $string['rule_phpdocsinvalidinlinetag'] = 'Inline phpdocs tags are valid'; @@ -55,9 +52,6 @@ $string['error_phpdoccontentsinlinetag'] = 'Inline phpdocs tag {$a->tag} with incorrect contents found. It must match {@link [valid URL] [description (optional)]} or {@see [valid FQSEN] [description (optional)]}'; $string['rule_phpdoccontentsinlinetag'] = 'Inline phpdocs tags have correct contents'; -$string['error_functiondescription'] = 'There is no description in phpdocs for function {$a->object}'; -$string['rule_functiondescription'] = 'Functions have descriptions in phpdocs'; - $string['error_functionarguments'] = 'Phpdocs for function {$a->function} has incomplete parameters list'; $string['rule_functionarguments'] = 'Phpdocs for functions properly define all parameters'; diff --git a/rules/phpdocs_basic.php b/rules/phpdocs_basic.php index d6c751e..6d73ef5 100644 --- a/rules/phpdocs_basic.php +++ b/rules/phpdocs_basic.php @@ -26,8 +26,6 @@ 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('definedoccorrect')->set_callback('local_moodlecheck_definedoccorrect'); local_moodlecheck_registry::add_rule('phpdocsinvalidinlinetag')->set_callback('local_moodlecheck_phpdocsinvalidinlinetag'); @@ -159,51 +157,6 @@ function local_moodlecheck_phpdoccontentsinlinetag(local_moodlecheck_file $file) return $errors; } -/** - * Makes sure that file-level phpdocs and all classes have one-line short description - * - * @param local_moodlecheck_file $file - * @return array of found errors - */ -function local_moodlecheck_phpdocsfistline(local_moodlecheck_file $file) { - $errors = []; - - if (($phpdocs = $file->find_file_phpdocs()) && !$file->find_file_phpdocs()->get_shortdescription()) { - $errors[] = [ - 'line' => $phpdocs->get_line_number($file), - 'object' => 'file', - ]; - } - foreach ($file->get_classes() as $class) { - if ($class->phpdocs && !$class->phpdocs->get_shortdescription()) { - $errors[] = [ - 'line' => $class->phpdocs->get_line_number($file), - 'object' => 'class '.$class->name, - ]; - } - } - return $errors; -} - -/** - * Makes sure that all functions have descriptions - * - * @param local_moodlecheck_file $file - * @return array of found errors - */ -function local_moodlecheck_functiondescription(local_moodlecheck_file $file) { - $errors = []; - foreach ($file->get_functions() as $function) { - if ($function->phpdocs !== false && !strlen($function->phpdocs->get_description())) { - $errors[] = [ - 'line' => $function->phpdocs->get_line_number($file), - 'object' => $function->name, - ]; - } - } - return $errors; -} - /** * Checks that all functions have proper arguments in phpdocs *