Skip to content

Commit 52e5f08

Browse files
authored
Merge pull request #100 from stronk7/boilerplate_sniff_and_empty_files
Avoid PHP error with BoilerplateComment and empty files
2 parents 4f7f6d6 + 3629cb2 commit 52e5f08

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

moodle/Sniffs/Files/BoilerplateCommentSniff.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public function process(File $file, $stackptr) {
7575
// Note that the opening PHP tag includes one newline.
7676
$numnewlines = 0;
7777
for ($i = $stackptr + 1; $i <= $stackptr + 5; ++$i) {
78-
if ($tokens[$i]['code'] == T_WHITESPACE && $tokens[$i]['content'] == "\n") {
78+
if (isset($tokens[$i]) && $tokens[$i]['code'] == T_WHITESPACE && $tokens[$i]['content'] == "\n") {
7979
$numnewlines++;
8080
} else {
8181
break;

moodle/Tests/FilesBoilerPlateCommentTest.php

+13
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,19 @@ public function test_moodle_files_boilerplatecomment_short() {
9292
$this->verify_cs_results();
9393
}
9494

95+
public function test_moodle_files_boilerplatecomment_short_empty() {
96+
$this->set_standard('moodle');
97+
$this->set_sniff('moodle.Files.BoilerplateComment');
98+
$this->set_fixture(__DIR__ . '/fixtures/files/boilerplatecomment/short_empty.php');
99+
100+
$this->set_errors([
101+
1 => 'FileTooShort',
102+
]);
103+
$this->set_warnings([]);
104+
105+
$this->verify_cs_results();
106+
}
107+
95108
public function test_moodle_files_boilerplatecomment_wrongline() {
96109
$this->set_standard('moodle');
97110
$this->set_sniff('moodle.Files.BoilerplateComment');
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<?php

0 commit comments

Comments
 (0)