From eb3262b41d9698df3b22b9d82fa109ce567b73df Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Wed, 13 Mar 2024 15:21:01 +0800 Subject: [PATCH 1/2] Remove noemptysecondlines check Already covered by: * moodle.Files.BoilerplateComment.NoPHP * PSR12.Files.FileHeader.HeaderPosition --- lang/en/local_moodlecheck.php | 3 --- rules/phpdocs_basic.php | 16 ---------------- tests/moodlecheck_rules_test.php | 2 -- 3 files changed, 21 deletions(-) diff --git a/lang/en/local_moodlecheck.php b/lang/en/local_moodlecheck.php index aeffcaf..1566f5a 100644 --- a/lang/en/local_moodlecheck.php +++ b/lang/en/local_moodlecheck.php @@ -37,9 +37,6 @@ $string['error_emptynophpfile'] = 'The file is empty or doesn\'t contain PHP code. Skipped.'; -$string['rule_noemptysecondline'] = 'Php open tag in the first line is not followed by empty line'; -$string['error_noemptysecondline'] = 'Empty line found after PHP open tag'; - $string['rule_filephpdocpresent'] = 'File-level phpdocs block is present'; $string['error_filephpdocpresent'] = 'File-level phpdocs block is not found'; diff --git a/rules/phpdocs_basic.php b/rules/phpdocs_basic.php index 4f73d6e..a235a13 100644 --- a/rules/phpdocs_basic.php +++ b/rules/phpdocs_basic.php @@ -24,8 +24,6 @@ defined('MOODLE_INTERNAL') || die; -local_moodlecheck_registry::add_rule('noemptysecondline')->set_callback('local_moodlecheck_noemptysecondline') - ->set_severity('warning'); local_moodlecheck_registry::add_rule('filephpdocpresent')->set_callback('local_moodlecheck_filephpdocpresent'); local_moodlecheck_registry::add_rule('classesdocumented')->set_callback('local_moodlecheck_classesdocumented'); local_moodlecheck_registry::add_rule('functionsdocumented')->set_callback('local_moodlecheck_functionsdocumented'); @@ -49,20 +47,6 @@ local_moodlecheck_registry::add_rule('phpdocsuncurlyinlinetag')->set_callback('local_moodlecheck_phpdocsuncurlyinlinetag'); local_moodlecheck_registry::add_rule('phpdoccontentsinlinetag')->set_callback('local_moodlecheck_phpdoccontentsinlinetag'); -/** - * Checks if the first line in the file has open tag and second line is not empty - * - * @param local_moodlecheck_file $file - * @return array of found errors - */ -function local_moodlecheck_noemptysecondline(local_moodlecheck_file $file) { - $tokens = &$file->get_tokens(); - if ($tokens[0][0] == T_OPEN_TAG && !$file->is_whitespace_token(1) && $file->is_multiline_token(0) == 1) { - return []; - } - return [['line' => 2]]; -} - /** * Checks if file-level phpdocs block is present * diff --git a/tests/moodlecheck_rules_test.php b/tests/moodlecheck_rules_test.php index 1a1d857..dd2b2a7 100644 --- a/tests/moodlecheck_rules_test.php +++ b/tests/moodlecheck_rules_test.php @@ -613,7 +613,6 @@ public function test_text_format_errors_and_warnings(): void { $result = $output->display_path($path, 'text'); $this->assertStringContainsString('tests/fixtures/error_and_warning.php', $result); - $this->assertStringContainsString('2: Empty line found after PHP open tag (warning)', $result); $this->assertStringContainsString('11: Class someclass is not documented (error)', $result); $this->assertStringContainsString('12: Function someclass::somefunc is not documented (warning)', $result); } @@ -632,7 +631,6 @@ public function test_html_format_errors_and_warnings(): void { $result = $output->display_path($path, 'html'); $this->assertStringContainsString('tests/fixtures/error_and_warning.php', $result); - $this->assertStringContainsString('2: Empty line found after PHP open tag (warning)', $result); $this->assertStringContainsString('11: Class someclass is not documented (error)', $result); $this->assertStringContainsString('12: Function someclass::somefunc is not documented (warning)', $result); } From e2986447a13fa64580f0f6d3eeb3a1f824b5436c Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Wed, 13 Mar 2024 15:37:21 +0800 Subject: [PATCH 2/2] Fix phpcs failures --- tests/moodlecheck_rules_test.php | 2 +- tests/phpdocs_basic_test.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/moodlecheck_rules_test.php b/tests/moodlecheck_rules_test.php index dd2b2a7..eaf9253 100644 --- a/tests/moodlecheck_rules_test.php +++ b/tests/moodlecheck_rules_test.php @@ -27,7 +27,7 @@ * @copyright 2018 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com} * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class moodlecheck_rules_test extends \advanced_testcase { +final class moodlecheck_rules_test extends \advanced_testcase { public function setUp(): void { global $CFG; parent::setUp(); diff --git a/tests/phpdocs_basic_test.php b/tests/phpdocs_basic_test.php index 7d98d4b..a18a469 100644 --- a/tests/phpdocs_basic_test.php +++ b/tests/phpdocs_basic_test.php @@ -24,7 +24,7 @@ * @copyright 2023 Andrew Lyons * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class phpdocs_basic_test extends \advanced_testcase { +final class phpdocs_basic_test extends \advanced_testcase { public static function setUpBeforeClass(): void { global $CFG;