moodlehq / moodle-local_codechecker

A Moodle local plugin providing a simple web UI to run the MoodleCS coding style checks with PHP_CodeSniffer.
63 stars 72 forks source link

Fix-198: Corrected handling of empty files. #199

Closed michael-milette closed 2 years ago

michael-milette commented 2 years ago

This fixes the handling of empty files. For more information, see #198 .

Let me know if you have any questions or concerns.

Best regards,

Michael Milette

stronk7 commented 2 years ago

Thanks @michael-milette,

I was going to create a PR with this solution:

--- a/locallib.php
+++ b/locallib.php
@@ -194,7 +194,7 @@ function local_codechecker_get_line_of_code($line, $prettypath) {
         $file = file($CFG->dirroot . '/' . $prettypath);
         $lastfilename = $prettypath;
     }
-    $linecontents = $file[$line - 1];
+    $linecontents = $file[$line - 1] ?? '';
     // Handle empty lines.
     if (trim($linecontents) === '') {
         $linecontents = 'Ø';

But yours is pretty equivalent, so I'll proceed to merge this once all tests have ended.

Ciao :-)