diff --git a/file.php b/file.php index 26e214c..0d2e609 100644 --- a/file.php +++ b/file.php @@ -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: @@ -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 = [ diff --git a/lang/en/local_moodlecheck.php b/lang/en/local_moodlecheck.php index a0f2082..82f93c1 100644 --- a/lang/en/local_moodlecheck.php +++ b/lang/en/local_moodlecheck.php @@ -48,15 +48,6 @@ $string['error_phpdocsfistline'] = 'No one-line description found in phpdocs for {$a->object}'; $string['rule_phpdocsfistline'] = 'File-level phpdocs block and class phpdocs should have one-line short description'; -$string['error_phpdocsinvalidtag'] = 'Invalid phpdocs tag {$a->tag} used'; -$string['rule_phpdocsinvalidtag'] = 'Used phpdocs tags are valid'; - -$string['error_phpdocsnotrecommendedtag'] = 'Not recommended phpdocs tag {$a->tag} used'; -$string['rule_phpdocsnotrecommendedtag'] = 'Used phpdocs tags are recommended'; - -$string['error_phpdocsinvalidpathtag'] = 'Incorrect path for phpdocs tag {$a->tag} detected'; -$string['rule_phpdocsinvalidpathtag'] = 'Used phpdocs tags have correct paths'; - $string['error_phpdocsinvalidinlinetag'] = 'Invalid inline phpdocs tag {$a->tag} found'; $string['rule_phpdocsinvalidinlinetag'] = 'Inline phpdocs tags are valid'; @@ -77,9 +68,3 @@ $string['rule_categoryvalid'] = 'Category tag is valid'; $string['error_categoryvalid'] = 'Category {$a->category} 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'; diff --git a/rules/phpdocs_basic.php b/rules/phpdocs_basic.php index 366a0a3..76fceab 100644 --- a/rules/phpdocs_basic.php +++ b/rules/phpdocs_basic.php @@ -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'); @@ -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 * @@ -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 []; -} diff --git a/tests/fixtures/anonymous/anonymous.php b/tests/fixtures/anonymous/anonymous.php deleted file mode 100644 index 68c0d16..0000000 --- a/tests/fixtures/anonymous/anonymous.php +++ /dev/null @@ -1,28 +0,0 @@ -. - -/** - * Unit tests for a fixture file in moodlecheck. - * - * @package local_moodlecheck - * @copyright 2020 Andrew Nicols - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -defined('MOODLE_INTERNAL') || die(); - -return new class { -}; diff --git a/tests/fixtures/anonymous/anonymous_with_params.php b/tests/fixtures/anonymous/anonymous_with_params.php deleted file mode 100644 index 4803466..0000000 --- a/tests/fixtures/anonymous/anonymous_with_params.php +++ /dev/null @@ -1,34 +0,0 @@ -. - -/** - * Unit tests for a fixture file in moodlecheck. - * - * @package local_moodlecheck - * @copyright 2023 onwards Eloy Lafuente (stronk7) {@link https://stronk7.com} - * @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -defined('MOODLE_INTERNAL') || die(); - -return new class ( - 10, - $units, - new something(), - $end -) -{ -}; diff --git a/tests/fixtures/anonymous/assigned.php b/tests/fixtures/anonymous/assigned.php deleted file mode 100644 index 9b6513c..0000000 --- a/tests/fixtures/anonymous/assigned.php +++ /dev/null @@ -1,28 +0,0 @@ -. - -/** - * Unit tests for a fixture file in moodlecheck. - * - * @package local_moodlecheck - * @copyright 2020 Andrew Nicols - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -defined('MOODLE_INTERNAL') || die(); - -$value = new class { -}; diff --git a/tests/fixtures/anonymous/extends.php b/tests/fixtures/anonymous/extends.php deleted file mode 100644 index 3663580..0000000 --- a/tests/fixtures/anonymous/extends.php +++ /dev/null @@ -1,28 +0,0 @@ -. - -/** - * Unit tests for a fixture file in moodlecheck. - * - * @package local_moodlecheck - * @copyright 2020 Andrew Nicols - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -defined('MOODLE_INTERNAL') || die(); - -return new class extends parentclass { -}; diff --git a/tests/fixtures/anonymous/extends_with_params.php b/tests/fixtures/anonymous/extends_with_params.php deleted file mode 100644 index 0100120..0000000 --- a/tests/fixtures/anonymous/extends_with_params.php +++ /dev/null @@ -1,28 +0,0 @@ -. - -/** - * Unit tests for a fixture file in moodlecheck. - * - * @package local_moodlecheck - * @copyright 2023 onwards Eloy Lafuente (stronk7) {@link https://stronk7.com} - * @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -defined('MOODLE_INTERNAL') || die(); - -return new class (10, $units, new something(), $end) extends parentclass { -}; diff --git a/tests/fixtures/anonymous/extendsandimplements.php b/tests/fixtures/anonymous/extendsandimplements.php deleted file mode 100644 index e01fdf8..0000000 --- a/tests/fixtures/anonymous/extendsandimplements.php +++ /dev/null @@ -1,28 +0,0 @@ -. - -/** - * Unit tests for a fixture file in moodlecheck. - * - * @package local_moodlecheck - * @copyright 2020 Andrew Nicols - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -defined('MOODLE_INTERNAL') || die(); - -return new class extends parentclass implements someinterface { -}; diff --git a/tests/fixtures/anonymous/implements.php b/tests/fixtures/anonymous/implements.php deleted file mode 100644 index 86906f8..0000000 --- a/tests/fixtures/anonymous/implements.php +++ /dev/null @@ -1,28 +0,0 @@ -. - -/** - * Unit tests for a fixture file in moodlecheck. - * - * @package local_moodlecheck - * @copyright 2020 Andrew Nicols - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -defined('MOODLE_INTERNAL') || die(); - -return new class implements someinterface { -}; diff --git a/tests/fixtures/anonymous/implements_with_params.php b/tests/fixtures/anonymous/implements_with_params.php deleted file mode 100644 index cd56091..0000000 --- a/tests/fixtures/anonymous/implements_with_params.php +++ /dev/null @@ -1,28 +0,0 @@ -. - -/** - * Unit tests for a fixture file in moodlecheck. - * - * @package local_moodlecheck - * @copyright 2023 onwards Eloy Lafuente (stronk7) {@link https://stronk7.com} - * @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -defined('MOODLE_INTERNAL') || die(); - -return new class (10, $units, new something(), $end) implements someinterface { -}; diff --git a/tests/fixtures/anonymous/named.php b/tests/fixtures/anonymous/named.php deleted file mode 100644 index c9451e4..0000000 --- a/tests/fixtures/anonymous/named.php +++ /dev/null @@ -1,28 +0,0 @@ -. - -/** - * Unit tests for a fixture file in moodlecheck. - * - * @package local_moodlecheck - * @copyright 2020 Andrew Nicols - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -namespace local_moodlecheck\test\fixtures\anonymous; - -class someclass extends parentclass { -} diff --git a/tests/fixtures/classtags.php b/tests/fixtures/classtags.php deleted file mode 100644 index 0a01c9e..0000000 --- a/tests/fixtures/classtags.php +++ /dev/null @@ -1,29 +0,0 @@ -. - -/** - * Fixture file providing a class. - * - * @package local_moodlecheck - * @copyright 2018 David Mudrák - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -/** - * This is a dummy class without any tags. - */ -class dummy_class_without_tags { -} diff --git a/tests/fixtures/phpdoc_constructor_property_promotion_readonly.php b/tests/fixtures/phpdoc_constructor_property_promotion_readonly.php new file mode 100644 index 0000000..252e70e --- /dev/null +++ b/tests/fixtures/phpdoc_constructor_property_promotion_readonly.php @@ -0,0 +1,50 @@ +. + +namespace local_moodlecheck; + +use cm_info; +use stdClass; + +/** + * A fixture to verify phpdoc tags used in constructor property promotion. + * + * @package local_moodlecheck + * @copyright 2023 Andrew Lyons + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class constructor_property_promotion { + /** + * An example of a constructor using constructor property promotion. + * + * @param stdClass|cm_info $cm The course module data + * @param string $name The name + * @param int|float $size The size + * @param null|string $description The description + * @param ?string $content The content + */ + public function __construct( + private stdClass|cm_info $cm, + /** @var string The name of the course module */ + public readonly string $name, + /** @var float|int The size */ + public readonly float|int $size, + /** @var null|string The description */ + protected readonly ?string $description = null, + protected ?string $content = null + ) { + } +} diff --git a/tests/fixtures/phpdoc_file_required_no1.php b/tests/fixtures/phpdoc_file_required_no1.php deleted file mode 100644 index bfce229..0000000 --- a/tests/fixtures/phpdoc_file_required_no1.php +++ /dev/null @@ -1,22 +0,0 @@ -. - -/** - * This is a dummy class without any tags. - */ -class dummy_fileclass_without_tags { - // As far as this is an 1-artifact file, the file phpdoc block is not required. -} diff --git a/tests/fixtures/phpdoc_file_required_no2.php b/tests/fixtures/phpdoc_file_required_no2.php deleted file mode 100644 index 349c3b1..0000000 --- a/tests/fixtures/phpdoc_file_required_no2.php +++ /dev/null @@ -1,22 +0,0 @@ -. - -/** - * This is a dummy interface without any tags. - */ -interface dummy_fileinterface_without_tags { - // As far as this is an 1-artifact file, the file phpdoc block is not required. -} diff --git a/tests/fixtures/phpdoc_file_required_no3.php b/tests/fixtures/phpdoc_file_required_no3.php deleted file mode 100644 index a16d3fc..0000000 --- a/tests/fixtures/phpdoc_file_required_no3.php +++ /dev/null @@ -1,22 +0,0 @@ -. - -/** - * This is a dummy trait without any tags. - */ -trait dummy_filetrait_without_tags { - // As far as this is an 1-artifact file, the file phpdoc block is not required. -} diff --git a/tests/fixtures/phpdoc_file_required_yes1.php b/tests/fixtures/phpdoc_file_required_yes1.php deleted file mode 100644 index cc6f899..0000000 --- a/tests/fixtures/phpdoc_file_required_yes1.php +++ /dev/null @@ -1,29 +0,0 @@ -. - -defined('MOODLE_INTERNAL') || die(); - -/** - * This is a dummy class without any tags. - */ -class dummy_fileclass1_without_tags { -} - -/** - * This is another dummy class without any tags. Hence, file phpdoc block is required. - */ -class dummy2_fileclass2_without_tags { -} diff --git a/tests/fixtures/phpdoc_file_required_yes2.php b/tests/fixtures/phpdoc_file_required_yes2.php deleted file mode 100644 index 3138bf1..0000000 --- a/tests/fixtures/phpdoc_file_required_yes2.php +++ /dev/null @@ -1,21 +0,0 @@ -. - -// This is library-style php file, no classes around. - -function dummy_filefunction_without_tags() { - // No classes, hence the file phpdoc block is required. -} diff --git a/tests/fixtures/phpdoc_file_required_yes3.php b/tests/fixtures/phpdoc_file_required_yes3.php deleted file mode 100644 index 9b093bf..0000000 --- a/tests/fixtures/phpdoc_file_required_yes3.php +++ /dev/null @@ -1,29 +0,0 @@ -. - -defined('MOODLE_INTERNAL') || die(); - -/** - * This is a dummy interface without any tags. - */ -interface dummy_fileinterface1_without_tags { -} - -/** - * This is a dummy trait without any tags. Hence, file phpdoc block is required. - */ -trait dummy_filetrait1_without_tags { -} diff --git a/tests/fixtures/phpdoc_method_overrides.php b/tests/fixtures/phpdoc_method_overrides.php deleted file mode 100644 index d502b5c..0000000 --- a/tests/fixtures/phpdoc_method_overrides.php +++ /dev/null @@ -1,35 +0,0 @@ -. - -interface dummy_top_level { - // Should be an error. - public function undocumented(); -} - -class dummy_implements_something implements dummy_top_level { - // Should be a warning. - public function undocumented() {} -} - -class dummy_extends_something extends dummy_implements_something { - // Should be a warning. - public function undocumented() {} -} - -class dummy_extends_and_implements_something extends dummy_implements_something implements dummy_top_level { - // Should be a warning. - public function undocumented() {} -} diff --git a/tests/fixtures/phpdoc_phpunit_coverage_ignored.php b/tests/fixtures/phpdoc_phpunit_coverage_ignored.php deleted file mode 100644 index f0f93a0..0000000 --- a/tests/fixtures/phpdoc_phpunit_coverage_ignored.php +++ /dev/null @@ -1,28 +0,0 @@ -. - -namespace local_moodlecheck; - -/** - * A fixture to verify various phpdoc tags in a tests location. - * - * @package local_moodlecheck - * @copyright 2018 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com} - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - * @codeCoverageIgnore - */ -class phpdoc_phpunit_coverage_ignored { -} diff --git a/tests/fixtures/phpdoc_tags_test.php b/tests/fixtures/phpdoc_tags_test.php deleted file mode 100644 index 045e514..0000000 --- a/tests/fixtures/phpdoc_tags_test.php +++ /dev/null @@ -1,85 +0,0 @@ -. - -// phpcs:ignoreFile - -/** - * A fixture to verify various phpdoc tags in a tests location. - * - * @package local_moodlecheck - * @copyright 2018 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com} - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -defined('MOODLE_INTERNAL') || die(); - -global $CFG; - -/** - * A fixture to verify various phpdoc tags in a tests location. - * - * @package local_moodlecheck - * @copyright 2018 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com} - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ -class fixturing_tests { - - /** - * Some valid tags, to verify they are ok. - * - * @license - * @throws - * @deprecated - * @author - * @todo - */ - public function all_valid_tags() { - echo "yay!"; - } - - /** - * Some more valid tags, because we are under tests area. - * - * @covers - * @dataProvider - * @group - * @runTestsInSeparateProcesses - */ - public function also_all_valid_tags() { - echo "reyay!"; - } - - /** - * Some more valid tags, because we are under tests area. - * - */ - public function valid_inline_tags() { - // @codeCoverageIgnoreStart - echo "reyay!"; - // @codeCoverageIgnoreEnd - } - - /** - * Some invalid tags. - * - * @small - * @zzzing - * @inheritdoc - */ - public function all_invalid_tags() { - echo "yoy!"; - } -} diff --git a/tests/moodlecheck_rules_test.php b/tests/moodlecheck_rules_test.php index f1029aa..50ba0a1 100644 --- a/tests/moodlecheck_rules_test.php +++ b/tests/moodlecheck_rules_test.php @@ -73,24 +73,6 @@ public function test_constantclass(): void { $this->assertSame(0, $found->length); } - /** - * Assert that classes do not need to have any particular phpdocs tags. - * - * @covers ::local_moodlecheck_filehascopyright - * @covers ::local_moodlecheck_filehaslicense - */ - public function test_classtags(): void { - global $PAGE; - - $output = $PAGE->get_renderer('local_moodlecheck'); - $path = new local_moodlecheck_path('local/moodlecheck/tests/fixtures/classtags.php ', null); - - $result = $output->display_path($path, 'xml'); - - $this->assertStringNotContainsString('classeshavecopyright', $result); - $this->assertStringNotContainsString('classeshavelicense', $result); - } - /** * Ensure that token_get_all() does not return PHP Warnings. * @@ -125,7 +107,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); @@ -138,13 +120,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); @@ -174,6 +149,33 @@ public function test_phpdoc_constructor_property_promotion(): void { $this->assertStringNotContainsString('constructor_property_promotion::__construct has incomplete parameters list', $result); } + /** + * Verify that constructor property promotion supports readonly properties. + * + * @covers ::local_moodlecheck_functionarguments + * @requires PHP >= 8.1 + */ + public function test_phpdoc_constructor_property_promotion_readonly(): void { + global $PAGE; + $output = $PAGE->get_renderer('local_moodlecheck'); + $path = new local_moodlecheck_path( + 'local/moodlecheck/tests/fixtures/phpdoc_constructor_property_promotion_readonly.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 8 children. + $xpath = new \DOMXpath($xmlresult); + $found = $xpath->query("//file/error"); + + $this->assertCount(0, $found); + $this->assertStringNotContainsString('constructor_property_promotion::__construct has incomplete parameters list', $result); + } + /** * Verify that constructor property promotion is supported. * @@ -222,66 +224,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 */