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 noinlinephpdocs check #144

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
48 changes: 0 additions & 48 deletions file.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ class local_moodlecheck_file {
protected $filephpdocs = null;
protected $allphpdocs = null;
protected $variables = null;
protected $defines = null;

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

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

/**
* Returns all 'define' statements found in file
*
* Returns array of objects where each element represents a define statement:
* $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_defines() {
if ($this->defines === null) {
$this->defines = [];
$this->get_tokens();
for ($tid = 0; $tid < $this->tokenscount; $tid++) {
if ($this->tokens[$tid][0] == T_STRING && $this->tokens[$tid][1] == 'define' &&
!$this->is_inside_function($tid) && !$this->is_inside_class($tid)) {
$next1id = $this->next_nonspace_token($tid, true);
$next1 = $this->next_nonspace_token($tid, false);
$next2 = $this->next_nonspace_token($next1id, false);
$variable = new stdClass;
$variable->tid = $tid;
if ($next1 == '(' && preg_match("/^(['\"])(.*)\\1$/", $next2, $matches)) {
$variable->fullname = $variable->name = $matches[2];
}
$variable->phpdocs = $this->find_preceeding_phpdoc($tid);
$variable->boundaries = $this->find_object_boundaries($variable);
$defines[] = $variable;
}
}
}
return $this->defines;
}

/**
* Finds and returns object boundaries
*
Expand Down Expand Up @@ -1240,15 +1201,6 @@ public function is_broken_description() {
return $this->brokentext;
}

/**
* Returns true if this is an inline phpdoc comment (starting with three slashes)
*
* @return bool
*/
public function is_inline() {
return preg_match('|^\s*///|', $this->originaltoken[1]);
}

/**
* Returns the original token storing this phpdocs
*
Expand Down
9 changes: 0 additions & 9 deletions lang/en/local_moodlecheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,6 @@

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

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

$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_phpdocsinvalidinlinetag'] = 'Invalid inline phpdocs tag <b>{$a->tag}</b> found';
$string['rule_phpdocsinvalidinlinetag'] = 'Inline phpdocs tags are valid';

Expand All @@ -55,8 +49,5 @@
$string['error_functionarguments'] = 'Phpdocs for function <b>{$a->function}</b> has incomplete parameters list';
$string['rule_functionarguments'] = 'Phpdocs for functions properly define all parameters';

$string['error_definedoccorrect'] = 'Phpdocs for define statement must start with constant name and dash: <b>{$a->object}</b>';
$string['rule_definedoccorrect'] = 'Check syntax for define statement';

$string['rule_categoryvalid'] = 'Category tag is valid';
$string['error_categoryvalid'] = 'Category <b>{$a->category}</b> is not valid';
54 changes: 0 additions & 54 deletions rules/phpdocs_basic.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,46 +24,11 @@

defined('MOODLE_INTERNAL') || die;

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('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');
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_definesdocumented(local_moodlecheck_file $file) {
$errors = [];
foreach ($file->get_defines() as $object) {
if ($object->phpdocs === false) {
$errors[] = ['object' => $object->fullname, 'line' => $file->get_line_number($object->tid)];
}
}
return $errors;
}

/**
* Checks that no comment starts with three or more slashes
*
* @param local_moodlecheck_file $file
* @return array of found errors
*/
function local_moodlecheck_noinlinephpdocs(local_moodlecheck_file $file) {
$errors = [];
foreach ($file->get_all_phpdocs() as $phpdocs) {
if ($phpdocs->is_inline()) {
$errors[] = ['line' => $phpdocs->get_line_number($file)];
}
}
return $errors;
}

/**
* Check that all the inline phpdoc tags found are valid
*
Expand Down Expand Up @@ -257,22 +222,3 @@ function($type) {

return implode('|', $types);
}

/**
* Checks that all define statement have constant name in phpdoc block
*
* @param local_moodlecheck_file $file
* @return array of found errors
*/
function local_moodlecheck_definedoccorrect(local_moodlecheck_file $file) {
$errors = [];
foreach ($file->get_defines() as $object) {
if ($object->phpdocs !== false) {
if (!preg_match('/^\s*'.$object->name.'\s+-\s+(.*)/', $object->phpdocs->get_description(), $matches) ||
!strlen(trim($matches[1]))) {
$errors[] = ['line' => $object->phpdocs->get_line_number($file), 'object' => $object->fullname];
}
}
}
return $errors;
}
Loading