Skip to content

Commit

Permalink
Remove phpdocsinvalidtag, phpdocsnotrecommendedtag, phpdocsinvalidpat…
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewnicols committed Mar 18, 2024
1 parent d4983eb commit 9e18f85
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 148 deletions.
9 changes: 0 additions & 9 deletions lang/en/local_moodlecheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,6 @@
$string['error_phpdocsfistline'] = 'No one-line description found in phpdocs for <b>{$a->object}</b>';
$string['rule_phpdocsfistline'] = 'File-level phpdocs block and class phpdocs should have one-line short description';

$string['error_phpdocsinvalidtag'] = 'Invalid phpdocs tag <b>{$a->tag}</b> used';
$string['rule_phpdocsinvalidtag'] = 'Used phpdocs tags are valid';

$string['error_phpdocsnotrecommendedtag'] = 'Not recommended phpdocs tag <b>{$a->tag}</b> used';
$string['rule_phpdocsnotrecommendedtag'] = 'Used phpdocs tags are recommended';

$string['error_phpdocsinvalidpathtag'] = 'Incorrect path for phpdocs tag <b>{$a->tag}</b> detected';
$string['rule_phpdocsinvalidpathtag'] = 'Used phpdocs tags have correct paths';

$string['error_phpdocsinvalidinlinetag'] = 'Invalid inline phpdocs tag <b>{$a->tag}</b> found';
$string['rule_phpdocsinvalidinlinetag'] = 'Inline phpdocs tags are valid';

Expand Down
74 changes: 0 additions & 74 deletions rules/phpdocs_basic.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,6 @@
local_moodlecheck_registry::add_rule('definedoccorrect')->set_callback('local_moodlecheck_definedoccorrect');
local_moodlecheck_registry::add_rule('filehascopyright')->set_callback('local_moodlecheck_filehascopyright');
local_moodlecheck_registry::add_rule('filehaslicense')->set_callback('local_moodlecheck_filehaslicense');
local_moodlecheck_registry::add_rule('phpdocsinvalidtag')->set_callback('local_moodlecheck_phpdocsinvalidtag');
local_moodlecheck_registry::add_rule('phpdocsnotrecommendedtag')->set_callback('local_moodlecheck_phpdocsnotrecommendedtag')
->set_severity('warning');
local_moodlecheck_registry::add_rule('phpdocsinvalidpathtag')->set_callback('local_moodlecheck_phpdocsinvalidpathtag')
->set_severity('warning');
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');
Expand Down Expand Up @@ -108,75 +103,6 @@ function local_moodlecheck_noinlinephpdocs(local_moodlecheck_file $file) {
return $errors;
}

/**
* Check that all the phpdoc tags used are valid ones
*
* @param local_moodlecheck_file $file
* @return array of found errors
*/
function local_moodlecheck_phpdocsinvalidtag(local_moodlecheck_file $file) {
$errors = [];
foreach ($file->get_all_phpdocs() as $phpdocs) {
foreach ($phpdocs->get_tags() as $tag) {
$tag = preg_replace('|^@([^\s]*).*|s', '$1', $tag);
if (!in_array($tag, local_moodlecheck_phpdocs::$validtags)) {
$errors[] = [
'line' => $phpdocs->get_line_number($file, '@' . $tag),
'tag' => '@' . $tag, ];
}
}
}
return $errors;
}

/**
* Check that all the phpdoc tags used are recommended ones
*
* @param local_moodlecheck_file $file
* @return array of found errors
*/
function local_moodlecheck_phpdocsnotrecommendedtag(local_moodlecheck_file $file) {
$errors = [];
foreach ($file->get_all_phpdocs() as $phpdocs) {
foreach ($phpdocs->get_tags() as $tag) {
$tag = preg_replace('|^@([^\s]*).*|s', '$1', $tag);
if (in_array($tag, local_moodlecheck_phpdocs::$validtags) &&
!in_array($tag, local_moodlecheck_phpdocs::$recommendedtags)) {
$errors[] = [
'line' => $phpdocs->get_line_number($file, '@' . $tag),
'tag' => '@' . $tag, ];
}
}
}
return $errors;
}

/**
* Check that all the path-restricted phpdoc tags used are in place
*
* @param local_moodlecheck_file $file
* @return array of found errors
*/
function local_moodlecheck_phpdocsinvalidpathtag(local_moodlecheck_file $file) {
$errors = [];
foreach ($file->get_all_phpdocs() as $phpdocs) {
foreach ($phpdocs->get_tags() as $tag) {
$tag = preg_replace('|^@([^\s]*).*|s', '$1', $tag);
if (in_array($tag, local_moodlecheck_phpdocs::$validtags) &&
in_array($tag, local_moodlecheck_phpdocs::$recommendedtags) &&
isset(local_moodlecheck_phpdocs::$pathrestrictedtags[$tag])) {
// Verify file path matches some of the valid paths for the tag.
if (!preg_filter(local_moodlecheck_phpdocs::$pathrestrictedtags[$tag], '$0', $file->get_filepath())) {
$errors[] = [
'line' => $phpdocs->get_line_number($file, '@' . $tag),
'tag' => '@' . $tag, ];
}
}
}
}
return $errors;
}

/**
* Check that all the inline phpdoc tags found are valid
*
Expand Down
66 changes: 1 addition & 65 deletions tests/moodlecheck_rules_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public function test_phpdoc_tags_general(): void {
$xpath = new \DOMXpath($xmlresult);
$found = $xpath->query("//file/error");
// TODO: Change to DOMNodeList::count() when php71 support is gone.
$this->assertSame(17, $found->length);
$this->assertSame(10, $found->length);

// Also verify various bits by content.
$this->assertStringContainsString('incomplete_param_annotation has incomplete parameters list', $result);
Expand All @@ -138,13 +138,6 @@ public function test_phpdoc_tags_general(): void {
$this->assertStringContainsString('mismatch_param_types2 has incomplete parameters list', $result);
$this->assertStringContainsString('mismatch_param_types3 has incomplete parameters list', $result);
$this->assertStringContainsString('incomplete_return_annotation has incomplete parameters list', $result);
$this->assertStringContainsString('Invalid phpdocs tag @small', $result);
$this->assertStringContainsString('Invalid phpdocs tag @zzzing', $result);
$this->assertStringContainsString('Invalid phpdocs tag @inheritdoc', $result);
$this->assertStringContainsString('Incorrect path for phpdocs tag @covers', $result);
$this->assertStringContainsString('Incorrect path for phpdocs tag @dataProvider', $result);
$this->assertStringContainsString('Incorrect path for phpdocs tag @group', $result);
$this->assertStringContainsString('@codingStandardsIgnoreLine', $result);
$this->assertStringNotContainsString('@deprecated', $result);
$this->assertStringNotContainsString('correct_param_types', $result);
$this->assertStringNotContainsString('correct_return_type', $result);
Expand Down Expand Up @@ -222,66 +215,9 @@ public function test_phpdoc_union_types(): void {
);
}

/**
* Verify various phpdoc tags in tests directories.
*
* @covers ::local_moodlecheck_phpdocsinvalidtag
* @covers ::local_moodlecheck_phpdocsnotrecommendedtag
* @covers ::local_moodlecheck_phpdocsinvalidpathtag
*/
public function test_phpdoc_tags_tests(): void {
global $PAGE;
$output = $PAGE->get_renderer('local_moodlecheck');
$path = new local_moodlecheck_path('local/moodlecheck/tests/fixtures/phpdoc_tags_test.php ', null);
$result = $output->display_path($path, 'xml');

// Convert results to XML Objext.
$xmlresult = new \DOMDocument();
$xmlresult->loadXML($result);

// Let's verify we have received a xml with file top element and 5 children.
$xpath = new \DOMXpath($xmlresult);
$found = $xpath->query("//file/error");
// TODO: Change to DOMNodeList::count() when php71 support is gone.
$this->assertSame(3, $found->length);

// Also verify various bits by content.
$this->assertStringContainsString('Invalid phpdocs tag @small', $result);
$this->assertStringContainsString('Invalid phpdocs tag @zzzing', $result);
$this->assertStringContainsString('Invalid phpdocs tag @inheritdoc', $result);
$this->assertStringNotContainsString('Incorrect path for phpdocs tag @covers', $result);
$this->assertStringNotContainsString('Incorrect path for phpdocs tag @dataProvider', $result);
$this->assertStringNotContainsString('Incorrect path for phpdocs tag @group', $result);
$this->assertStringNotContainsString('@deprecated', $result);
}

/**
* Verify phpunit codeCoverageIgnore can be applied to an entire file.
*
* @covers ::local_moodlecheck_phpdocsinvalidtag
*/
public function test_phpdoc_phpunit_coverage_ignored_for_file(): void {
global $PAGE;
$output = $PAGE->get_renderer('local_moodlecheck');
$path = new local_moodlecheck_path('local/moodlecheck/tests/fixtures/phpdoc_phpunit_coverage_ignored.php ', null);
$result = $output->display_path($path, 'xml');

// Convert results to XML Objext.
$xmlresult = new \DOMDocument();
$xmlresult->loadXML($result);

// Let's verify we have received a xml with file top element and 5 children.
$xpath = new \DOMXpath($xmlresult);
$found = $xpath->query("//file/error");

// TODO: Change to DOMNodeList::count() when php71 support is gone.
$this->assertSame(0, $found->length);
}

/**
* Verify various phpdoc tags can be used inline.
*
* @covers ::local_moodlecheck_phpdocsinvalidinlinetag
* @covers ::local_moodlecheck_phpdocsuncurlyinlinetag
* @covers ::local_moodlecheck_phpdoccontentsinlinetag
*/
Expand Down

0 comments on commit 9e18f85

Please sign in to comment.