Skip to content

Commit

Permalink
Merge branch 'main' into variablesdocumentedRemoval
Browse files Browse the repository at this point in the history
  • Loading branch information
stronk7 authored Mar 19, 2024
2 parents 70b6c31 + 5398c9c commit aa18a06
Show file tree
Hide file tree
Showing 24 changed files with 87 additions and 846 deletions.
73 changes: 9 additions & 64 deletions file.php
Original file line number Diff line number Diff line change
Expand Up @@ -423,8 +423,16 @@ public function &get_functions() {
$argtokens = array_values($argtokens);

for ($j = 0; $j < count($argtokens); $j++) {
if (version_compare(PHP_VERSION, '8.1.0') >= 0) {
// T_READONLY introduced in PHP 8.1.
if ($argtokens[$j][0] === T_READONLY) {
continue;
}
}
switch ($argtokens[$j][0]) {
// Skip any whitespace, or argument visibility.
case T_COMMENT:
case T_DOC_COMMENT:
case T_WHITESPACE:
case T_PUBLIC:
case T_PROTECTED:
Expand Down Expand Up @@ -1152,70 +1160,7 @@ class local_moodlecheck_phpdocs {
'var',
'version',
];
/** @var array static property storing the list of recommended
* phpdoc tags to use within Moodle phpdocs.
* @link http://docs.moodle.org/dev/Coding_style */
public static $recommendedtags = [
// Behat tags.
'Given',
'Then',
'When',
// PHPUnit tags.
'codeCoverageIgnore',
'codeCoverageIgnoreStart',
'codeCoverageIgnoreEnd',
'covers',
'coversDefaultClass',
'coversNothing',
'dataProvider',
'depends',
'group',
'requires',
'runTestsInSeparateProcesses',
'runInSeparateProcess',
'testWith',
'uses',
// PHPDoc tags.
'author',
'category',
'copyright',
'deprecated',
'license',
'link',
'package',
'param',
'property',
'property-read',
'property-write',
'return',
'see',
'since',
'subpackage',
'throws',
'todo',
'uses',
'var',
];
/** @var array static property storing the list of phpdoc tags
* allowed to be used under certain directories. keys are tags, values are
* arrays of allowed paths (regexp patterns).
*/
public static $pathrestrictedtags = [
'Given' => ['#.*/tests/behat/.*#'],
'Then' => ['#.*/tests/behat/.*#'],
'When' => ['#.*/tests/behat/.*#'],
'covers' => ['#.*/tests/.*_test.php#'],
'coversDefaultClass' => ['#.*/tests/.*_test.php#'],
'coversNothing' => ['#.*/tests/.*_test.php#'],
'dataProvider' => ['#.*/tests/.*_test.php#'],
'depends' => ['#.*/tests/.*_test.php#'],
'group' => ['#.*/tests/.*_test.php#'],
'requires' => ['#.*/tests/.*_test.php#'],
'runTestsInSeparateProcesses' => ['#.*/tests/.*_test.php#'],
'runInSeparateProcess' => ['#.*/tests/.*_test.php#'],
'testWith' => ['#.*/tests/.*_test.php#'],
// Commented out: 'uses' => ['#.*/tests/.*_test.php#'], can also be out from tests (Coding style dixit).
];

/** @var array static property storing the list of phpdoc tags
* allowed to be used inline within Moodle phpdocs. */
public static $inlinetags = [
Expand Down
15 changes: 0 additions & 15 deletions lang/en/local_moodlecheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,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 All @@ -77,9 +68,3 @@

$string['rule_categoryvalid'] = 'Category tag is valid';
$string['error_categoryvalid'] = 'Category <b>{$a->category}</b> is not valid';

$string['rule_filehascopyright'] = 'Files have @copyright tag';
$string['error_filehascopyright'] = 'File-level phpdocs block does not have @copyright tag';

$string['rule_filehaslicense'] = 'Files have @license tag';
$string['error_filehaslicense'] = 'File-level phpdocs block does not have @license tag';
104 changes: 0 additions & 104 deletions rules/phpdocs_basic.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,6 @@
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('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 @@ -90,75 +83,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 Expand Up @@ -416,31 +340,3 @@ function local_moodlecheck_definedoccorrect(local_moodlecheck_file $file) {
}
return $errors;
}

/**
* Makes sure that files have copyright tag
*
* @param local_moodlecheck_file $file
* @return array of found errors
*/
function local_moodlecheck_filehascopyright(local_moodlecheck_file $file) {
$phpdocs = $file->find_file_phpdocs();
if ($phpdocs && !count($phpdocs->get_tags('copyright', true))) {
return [['line' => $phpdocs->get_line_number($file, '@copyright')]];
}
return [];
}

/**
* Makes sure that files have license tag
*
* @param local_moodlecheck_file $file
* @return array of found errors
*/
function local_moodlecheck_filehaslicense(local_moodlecheck_file $file) {
$phpdocs = $file->find_file_phpdocs();
if ($phpdocs && !count($phpdocs->get_tags('license', true))) {
return [['line' => $phpdocs->get_line_number($file, '@license')]];
}
return [];
}
28 changes: 0 additions & 28 deletions tests/fixtures/anonymous/anonymous.php

This file was deleted.

34 changes: 0 additions & 34 deletions tests/fixtures/anonymous/anonymous_with_params.php

This file was deleted.

28 changes: 0 additions & 28 deletions tests/fixtures/anonymous/assigned.php

This file was deleted.

28 changes: 0 additions & 28 deletions tests/fixtures/anonymous/extends.php

This file was deleted.

28 changes: 0 additions & 28 deletions tests/fixtures/anonymous/extends_with_params.php

This file was deleted.

Loading

0 comments on commit aa18a06

Please sign in to comment.