Skip to content

Commit

Permalink
Remove variablesdocumented (moodlehq#135)
Browse files Browse the repository at this point in the history
Replaced by moodlehq/moodle-cs#121

Co-authored-by: Eloy Lafuente <[email protected]>
  • Loading branch information
andrewnicols and stronk7 authored Mar 19, 2024
1 parent 5398c9c commit 7bffe4d
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 143 deletions.
5 changes: 0 additions & 5 deletions lang/en/local_moodlecheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 <b>{$a->variable}</b> is not documented';
$string['rule_constsdocumented'] = 'All constants are documented';
$string['error_constsdocumented'] = 'Constant <b>{$a->object}</b> is not documented';
$string['rule_definesdocumented'] = 'All define statements are documented';
Expand All @@ -65,9 +63,6 @@
$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_variableshasvar'] = 'Phpdocs for variable <b>{$a->variable}</b> 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: <b>{$a->object}</b>';
$string['rule_definedoccorrect'] = 'Check syntax for define statement';

Expand Down
39 changes: 0 additions & 39 deletions rules/phpdocs_basic.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -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
*
Expand Down
56 changes: 0 additions & 56 deletions tests/fixtures/phpdoc_properties.php

This file was deleted.

43 changes: 0 additions & 43 deletions tests/moodlecheck_rules_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
*
Expand Down

0 comments on commit 7bffe4d

Please sign in to comment.