moodlehq / moodle-cs

Moodle Coding Style
https://github.com/moodlehq/moodle-cs
GNU General Public License v3.0
18 stars 16 forks source link

moodle.Files.BoilerplateComment fails on empty files #97

Closed micaherne closed 9 months ago

micaherne commented 9 months ago

Where a file has only an opening <?php tag, the BoilerplateComment sniff fails with the error message: An error occurred during processing; checking has been aborted. The error message was: Undefined array key 1 in /path/to/vendor/moodlehq/moodle-cs/moodle/Sniffs/Files/BoilerplateCommentSniff.php on line 78. The error originated in the moodle.Files.BoilerplateComment sniff on line 78

I would expect this not to fail but to let the user know that the copyright statement is missing.

You could argue that files like this shouldn't exist at all, but there are cases where they're necessary, for example moodle-plugin-ci's checks on plugins fail if lib.php is missing but there is often no need for any content in this.

stronk7 commented 9 months ago

Thanks @micaherne ,

I think I've fixed it here (missing isset() check), and now empty PHP files are reported with correct error:

FILE: /Users/stronk7/git_moodle/moodle-cs/test.php
------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
------------------------------------------------------------------------------------
 1 | ERROR | Reached the end of the file before finding all of the opening comment.
------------------------------------------------------------------------------------

I'm going to add some test and will create PR.

Ciao :-)