Skip to content

Commit 567fcd6

Browse files
authored
Merge pull request moodlehq#140 from andrewnicols/constsdocumented
Remove constsdocumented
2 parents 2c7f500 + 11e202d commit 567fcd6

File tree

4 files changed

+0
-85
lines changed

4 files changed

+0
-85
lines changed

file.php

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ class local_moodlecheck_file {
4747
protected $allphpdocs = null;
4848
protected $variables = null;
4949
protected $defines = null;
50-
protected $constants = null;
5150

5251
/**
5352
* Creates an object from path to the file
@@ -72,7 +71,6 @@ protected function clear_memory() {
7271
$this->allphpdocs = null;
7372
$this->variables = null;
7473
$this->defines = null;
75-
$this->constants = null;
7674
}
7775

7876
/**
@@ -518,47 +516,6 @@ public function &get_variables() {
518516
return $this->variables;
519517
}
520518

521-
/**
522-
* Returns all constants found in file
523-
*
524-
* Returns array of objects where each element represents a constant:
525-
* $variable->tid : token id of the token with variable name
526-
* $variable->name : name of the variable (starts with $)
527-
* $variable->phpdocs : phpdocs for this variable (instance of local_moodlecheck_phpdocs or false if not found)
528-
* $variable->class : containing class object
529-
* $variable->fullname : name of the variable with class name (i.e. classname::$varname)
530-
* $variable->boundaries : array with ids of first and last token for this constant
531-
*
532-
* @return array
533-
*/
534-
public function &get_constants() {
535-
if ($this->constants === null) {
536-
$this->constants = [];
537-
$this->get_tokens();
538-
for ($tid = 0; $tid < $this->tokenscount; $tid++) {
539-
if ($this->tokens[$tid][0] == T_USE) {
540-
// Skip the entire use statement, to avoid interpreting "use const" as a constant.
541-
$tid = $this->end_of_statement($tid);
542-
continue;
543-
}
544-
545-
if ($this->tokens[$tid][0] == T_CONST && !$this->is_inside_function($tid)) {
546-
$variable = new stdClass;
547-
$variable->tid = $tid;
548-
$variable->fullname = $variable->name = $this->next_nonspace_token($tid, false);
549-
$variable->class = $this->is_inside_class($tid);
550-
if ($variable->class !== false) {
551-
$variable->fullname = $variable->class->name . '::' . $variable->name;
552-
}
553-
$variable->phpdocs = $this->find_preceeding_phpdoc($tid);
554-
$variable->boundaries = $this->find_object_boundaries($variable);
555-
$this->constants[] = $variable;
556-
}
557-
}
558-
}
559-
return $this->constants;
560-
}
561-
562519
/**
563520
* Returns all 'define' statements found in file
564521
*

lang/en/local_moodlecheck.php

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

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

40-
$string['rule_constsdocumented'] = 'All constants are documented';
41-
$string['error_constsdocumented'] = 'Constant <b>{$a->object}</b> is not documented';
4240
$string['rule_definesdocumented'] = 'All define statements are documented';
4341
$string['error_definesdocumented'] = 'Define statement for <b>{$a->object}</b> is not documented';
4442

rules/phpdocs_basic.php

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424

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

27-
local_moodlecheck_registry::add_rule('constsdocumented')->set_callback('local_moodlecheck_constsdocumented');
2827
local_moodlecheck_registry::add_rule('definesdocumented')->set_callback('local_moodlecheck_definesdocumented');
2928
local_moodlecheck_registry::add_rule('noinlinephpdocs')->set_callback('local_moodlecheck_noinlinephpdocs');
3029
local_moodlecheck_registry::add_rule('phpdocsfistline')->set_callback('local_moodlecheck_phpdocsfistline');
@@ -35,22 +34,6 @@
3534
local_moodlecheck_registry::add_rule('phpdocsuncurlyinlinetag')->set_callback('local_moodlecheck_phpdocsuncurlyinlinetag');
3635
local_moodlecheck_registry::add_rule('phpdoccontentsinlinetag')->set_callback('local_moodlecheck_phpdoccontentsinlinetag');
3736

38-
/**
39-
* Checks if all constants have phpdocs blocks
40-
*
41-
* @param local_moodlecheck_file $file
42-
* @return array of found errors
43-
*/
44-
function local_moodlecheck_constsdocumented(local_moodlecheck_file $file) {
45-
$errors = [];
46-
foreach ($file->get_constants() as $object) {
47-
if ($object->phpdocs === false) {
48-
$errors[] = ['object' => $object->fullname, 'line' => $file->get_line_number($object->tid)];
49-
}
50-
}
51-
return $errors;
52-
}
53-
5437
/**
5538
* Checks if all variables have phpdocs blocks
5639
*

tests/moodlecheck_rules_test.php

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -324,29 +324,6 @@ public function test_j_method_multiline(): void {
324324
$this->assertSame(0, $found->length); // All examples in fixtures are ok.
325325
}
326326

327-
/**
328-
* Verify that "use function" statements are ignored.
329-
*
330-
* @covers ::local_moodlecheck_constsdocumented
331-
*/
332-
public function test_constsdocumented_ignore_uses(): void {
333-
$file = __DIR__ . "/fixtures/uses.php";
334-
335-
global $PAGE;
336-
$output = $PAGE->get_renderer('local_moodlecheck');
337-
$path = new local_moodlecheck_path($file, null);
338-
$result = $output->display_path($path, 'xml');
339-
340-
// Convert results to XML Object.
341-
$xmlresult = new \DOMDocument();
342-
$xmlresult->loadXML($result);
343-
344-
$xpath = new \DOMXpath($xmlresult);
345-
$found = $xpath->query('//file/error[@source="constsdocumented"]');
346-
// TODO: Change to DOMNodeList::count() when php71 support is gone.
347-
$this->assertSame(0, $found->length);
348-
}
349-
350327
/**
351328
* Verify that the text format shown information about the severity of the problem (error vs warning)
352329
*

0 commit comments

Comments
 (0)