Skip to content

Commit 48ff9d3

Browse files
committed
Remove all checks for define() (moodlehq#141)
These checks never worked. The `get_defines()` method built a list of definitions, added them to a `$defines` array, but return `$this->defines` instead. Furthermore there would be pandamonium if we actually fixed this because we use constants in scripts all over Moodle with the same value, for example: ``` define('CLI_SCRIPT', true); ```
1 parent 57b2699 commit 48ff9d3

File tree

3 files changed

+0
-82
lines changed

3 files changed

+0
-82
lines changed

file.php

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ class local_moodlecheck_file {
4646
protected $filephpdocs = null;
4747
protected $allphpdocs = null;
4848
protected $variables = null;
49-
protected $defines = null;
5049

5150
/**
5251
* Creates an object from path to the file
@@ -70,7 +69,6 @@ protected function clear_memory() {
7069
$this->filephpdocs = null;
7170
$this->allphpdocs = null;
7271
$this->variables = null;
73-
$this->defines = null;
7472
}
7573

7674
/**
@@ -516,43 +514,6 @@ public function &get_variables() {
516514
return $this->variables;
517515
}
518516

519-
/**
520-
* Returns all 'define' statements found in file
521-
*
522-
* Returns array of objects where each element represents a define statement:
523-
* $variable->tid : token id of the token with variable name
524-
* $variable->name : name of the variable (starts with $)
525-
* $variable->phpdocs : phpdocs for this variable (instance of local_moodlecheck_phpdocs or false if not found)
526-
* $variable->class : containing class object
527-
* $variable->fullname : name of the variable with class name (i.e. classname::$varname)
528-
* $variable->boundaries : array with ids of first and last token for this constant
529-
*
530-
* @return array
531-
*/
532-
public function &get_defines() {
533-
if ($this->defines === null) {
534-
$this->defines = [];
535-
$this->get_tokens();
536-
for ($tid = 0; $tid < $this->tokenscount; $tid++) {
537-
if ($this->tokens[$tid][0] == T_STRING && $this->tokens[$tid][1] == 'define' &&
538-
!$this->is_inside_function($tid) && !$this->is_inside_class($tid)) {
539-
$next1id = $this->next_nonspace_token($tid, true);
540-
$next1 = $this->next_nonspace_token($tid, false);
541-
$next2 = $this->next_nonspace_token($next1id, false);
542-
$variable = new stdClass;
543-
$variable->tid = $tid;
544-
if ($next1 == '(' && preg_match("/^(['\"])(.*)\\1$/", $next2, $matches)) {
545-
$variable->fullname = $variable->name = $matches[2];
546-
}
547-
$variable->phpdocs = $this->find_preceeding_phpdoc($tid);
548-
$variable->boundaries = $this->find_object_boundaries($variable);
549-
$defines[] = $variable;
550-
}
551-
}
552-
}
553-
return $this->defines;
554-
}
555-
556517
/**
557518
* Finds and returns object boundaries
558519
*

lang/en/local_moodlecheck.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,6 @@
3737

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

40-
$string['rule_definesdocumented'] = 'All define statements are documented';
41-
$string['error_definesdocumented'] = 'Define statement for <b>{$a->object}</b> is not documented';
42-
4340
$string['rule_noinlinephpdocs'] = 'There are no comments starting with three or more slashes';
4441
$string['error_noinlinephpdocs'] = 'Found comment starting with three or more slashes';
4542

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

58-
$string['error_definedoccorrect'] = 'Phpdocs for define statement must start with constant name and dash: <b>{$a->object}</b>';
59-
$string['rule_definedoccorrect'] = 'Check syntax for define statement';
60-
6155
$string['rule_categoryvalid'] = 'Category tag is valid';
6256
$string['error_categoryvalid'] = 'Category <b>{$a->category}</b> is not valid';

rules/phpdocs_basic.php

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -24,30 +24,12 @@
2424

2525
defined('MOODLE_INTERNAL') || die;
2626

27-
local_moodlecheck_registry::add_rule('definesdocumented')->set_callback('local_moodlecheck_definesdocumented');
2827
local_moodlecheck_registry::add_rule('noinlinephpdocs')->set_callback('local_moodlecheck_noinlinephpdocs');
2928
local_moodlecheck_registry::add_rule('functionarguments')->set_callback('local_moodlecheck_functionarguments');
30-
local_moodlecheck_registry::add_rule('definedoccorrect')->set_callback('local_moodlecheck_definedoccorrect');
3129
local_moodlecheck_registry::add_rule('phpdocsinvalidinlinetag')->set_callback('local_moodlecheck_phpdocsinvalidinlinetag');
3230
local_moodlecheck_registry::add_rule('phpdocsuncurlyinlinetag')->set_callback('local_moodlecheck_phpdocsuncurlyinlinetag');
3331
local_moodlecheck_registry::add_rule('phpdoccontentsinlinetag')->set_callback('local_moodlecheck_phpdoccontentsinlinetag');
3432

35-
/**
36-
* Checks if all variables have phpdocs blocks
37-
*
38-
* @param local_moodlecheck_file $file
39-
* @return array of found errors
40-
*/
41-
function local_moodlecheck_definesdocumented(local_moodlecheck_file $file) {
42-
$errors = [];
43-
foreach ($file->get_defines() as $object) {
44-
if ($object->phpdocs === false) {
45-
$errors[] = ['object' => $object->fullname, 'line' => $file->get_line_number($object->tid)];
46-
}
47-
}
48-
return $errors;
49-
}
50-
5133
/**
5234
* Checks that no comment starts with three or more slashes
5335
*
@@ -257,22 +239,3 @@ function($type) {
257239

258240
return implode('|', $types);
259241
}
260-
261-
/**
262-
* Checks that all define statement have constant name in phpdoc block
263-
*
264-
* @param local_moodlecheck_file $file
265-
* @return array of found errors
266-
*/
267-
function local_moodlecheck_definedoccorrect(local_moodlecheck_file $file) {
268-
$errors = [];
269-
foreach ($file->get_defines() as $object) {
270-
if ($object->phpdocs !== false) {
271-
if (!preg_match('/^\s*'.$object->name.'\s+-\s+(.*)/', $object->phpdocs->get_description(), $matches) ||
272-
!strlen(trim($matches[1]))) {
273-
$errors[] = ['line' => $object->phpdocs->get_line_number($file), 'object' => $object->fullname];
274-
}
275-
}
276-
}
277-
return $errors;
278-
}

0 commit comments

Comments
 (0)