diff --git a/moodle/Sniffs/Files/MoodleInternalSniff.php b/moodle/Sniffs/Files/MoodleInternalSniff.php index fdd239b..4ec3aaf 100644 --- a/moodle/Sniffs/Files/MoodleInternalSniff.php +++ b/moodle/Sniffs/Files/MoodleInternalSniff.php @@ -166,6 +166,9 @@ protected function get_position_of_relevant_code(File $file, $pointer) { } else if ($tokens[$pointer]['code'] === T_DECLARE && $tokens[$pointer]['content'] == 'declare') { // Declare statements must be at start of file. $pointer = $file->findEndOfStatement($pointer + 1); + } else if ($tokens[$pointer]['code'] === T_ATTRIBUTE) { + // Attribute statements must be at start of file. + $pointer = $tokens[$pointer]['attribute_closer'] + 1; } else { $relevantcodefound = true; } diff --git a/moodle/Tests/Sniffs/Files/MoodleInternalTest.php b/moodle/Tests/Sniffs/Files/MoodleInternalTest.php index a6f7beb..8e891e1 100644 --- a/moodle/Tests/Sniffs/Files/MoodleInternalTest.php +++ b/moodle/Tests/Sniffs/Files/MoodleInternalTest.php @@ -150,6 +150,11 @@ public static function provider(): array { ], [], ], + [ + 'attribute_ok', + [], + [], + ], ]; } } diff --git a/moodle/Tests/Sniffs/Files/fixtures/moodleinternal/attribute_ok.php b/moodle/Tests/Sniffs/Files/fixtures/moodleinternal/attribute_ok.php new file mode 100644 index 0000000..f75a4ff --- /dev/null +++ b/moodle/Tests/Sniffs/Files/fixtures/moodleinternal/attribute_ok.php @@ -0,0 +1,27 @@ +. + +/** + * Class with an attribute. + * + * @package core + * @copyright 2024 Andrew Lyons + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +#[\Attribute] +class example { +}