diff --git a/moodle/Sniffs/Files/BoilerplateCommentSniff.php b/moodle/Sniffs/Files/BoilerplateCommentSniff.php index fd27a37..8883171 100644 --- a/moodle/Sniffs/Files/BoilerplateCommentSniff.php +++ b/moodle/Sniffs/Files/BoilerplateCommentSniff.php @@ -75,7 +75,7 @@ public function process(File $file, $stackptr) { // Note that the opening PHP tag includes one newline. $numnewlines = 0; for ($i = $stackptr + 1; $i <= $stackptr + 5; ++$i) { - if ($tokens[$i]['code'] == T_WHITESPACE && $tokens[$i]['content'] == "\n") { + if (isset($tokens[$i]) && $tokens[$i]['code'] == T_WHITESPACE && $tokens[$i]['content'] == "\n") { $numnewlines++; } else { break; diff --git a/moodle/Tests/FilesBoilerPlateCommentTest.php b/moodle/Tests/FilesBoilerPlateCommentTest.php index 1c4c981..d6e77f5 100644 --- a/moodle/Tests/FilesBoilerPlateCommentTest.php +++ b/moodle/Tests/FilesBoilerPlateCommentTest.php @@ -92,6 +92,19 @@ public function test_moodle_files_boilerplatecomment_short() { $this->verify_cs_results(); } + public function test_moodle_files_boilerplatecomment_short_empty() { + $this->set_standard('moodle'); + $this->set_sniff('moodle.Files.BoilerplateComment'); + $this->set_fixture(__DIR__ . '/fixtures/files/boilerplatecomment/short_empty.php'); + + $this->set_errors([ + 1 => 'FileTooShort', + ]); + $this->set_warnings([]); + + $this->verify_cs_results(); + } + public function test_moodle_files_boilerplatecomment_wrongline() { $this->set_standard('moodle'); $this->set_sniff('moodle.Files.BoilerplateComment'); diff --git a/moodle/Tests/fixtures/files/boilerplatecomment/short_empty.php b/moodle/Tests/fixtures/files/boilerplatecomment/short_empty.php new file mode 100644 index 0000000..b3d9bbc --- /dev/null +++ b/moodle/Tests/fixtures/files/boilerplatecomment/short_empty.php @@ -0,0 +1 @@ +