Skip to content

Commit

Permalink
Merge pull request #100 from stronk7/boilerplate_sniff_and_empty_files
Browse files Browse the repository at this point in the history
Avoid PHP error with BoilerplateComment and empty files
  • Loading branch information
junpataleta authored Feb 15, 2024
2 parents 4f7f6d6 + 3629cb2 commit 52e5f08
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion moodle/Sniffs/Files/BoilerplateCommentSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
13 changes: 13 additions & 0 deletions moodle/Tests/FilesBoilerPlateCommentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php

0 comments on commit 52e5f08

Please sign in to comment.