From 2f2ba6c5846eb619af482c70e3b0f9969db9c27d Mon Sep 17 00:00:00 2001 From: "Eloy Lafuente (stronk7)" Date: Wed, 19 Jan 2022 11:14:01 +0100 Subject: [PATCH] Avoid comma-separated use statements to require MOODLE_INTERNAL No matter that comma-separated use statements are a violation of the coding style (see Namespaces section), they, for sure, don't constitute a side-effect at all, so the MOODLE_INTERNAL check should be immune to them. This fix just enables comma-separated to be properly processed, covered with tests. Fixes #175 --- moodle/Sniffs/Files/MoodleInternalSniff.php | 3 ++- .../fixtures/files/moodleinternal/namespace_with_use_ok.php | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/moodle/Sniffs/Files/MoodleInternalSniff.php b/moodle/Sniffs/Files/MoodleInternalSniff.php index e49b37d4..9a715301 100644 --- a/moodle/Sniffs/Files/MoodleInternalSniff.php +++ b/moodle/Sniffs/Files/MoodleInternalSniff.php @@ -154,7 +154,7 @@ protected function get_position_of_relevant_code(File $file, $pointer) { $pointer = $file->findNext($ignoredtokens, $pointer, null, true); if ($tokens[$pointer]['code'] === T_NAMESPACE || $tokens[$pointer]['code'] === T_USE) { // Namespace definitions are allowed before anything else, jump to end of namspace statement. - $pointer = $file->findEndOfStatement($pointer + 1); + $pointer = $file->findEndOfStatement($pointer + 1, T_COMMA); } else if ($tokens[$pointer]['code'] === T_STRING && $tokens[$pointer]['content'] == 'define') { // Some things like AJAX_SCRIPT NO_MOODLE_COOKIES need to be defined before config inclusion. // Jump to end of define(). @@ -321,6 +321,7 @@ private function code_changes_global_state(File $file, $start, $end) { continue; } + // Ignore function/class prefixes. if (isset(Tokens::$methodPrefixes[$tokens[$i]['code']]) === true) { continue; diff --git a/moodle/tests/fixtures/files/moodleinternal/namespace_with_use_ok.php b/moodle/tests/fixtures/files/moodleinternal/namespace_with_use_ok.php index 17a70df5..901a858e 100644 --- a/moodle/tests/fixtures/files/moodleinternal/namespace_with_use_ok.php +++ b/moodle/tests/fixtures/files/moodleinternal/namespace_with_use_ok.php @@ -24,6 +24,9 @@ namespace mod_workshop\plugininfo; use core\plugininfo\base; +use core\plugininfo\this, + core\plugininfo\that; +use core\plugininfo\one, core\plugininfo\two,core\plugininfo\three; class workshopallocation extends base { public function is_uninstall_allowed() {