r59036 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r59035‎ | r59036 | r59037 >
Date:22:18, 13 November 2009
Author:maxsem
Status:ok
Tags:
Comment:
Now syntaxChecker.php checks for typical coding errors such as BOMSs and trailing ?>
Modified paths:
  • /trunk/phase3/maintenance/syntaxChecker.php (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/syntaxChecker.php
@@ -25,7 +25,7 @@
2626 class SyntaxChecker extends Maintenance {
2727
2828 // List of files we're going to check
29 - private $mFiles, $mFailures = array();
 29+ private $mFiles, $mFailures = array(), $mWarnings = array();
3030
3131 public function __construct() {
3232 parent::__construct();
@@ -52,9 +52,11 @@
5353 } else {
5454 $this->checkFileWithCli( $f );
5555 }
 56+ $this->checkForMistakes( $f );
5657 }
5758 $this->output( "\nDone! " . count( $this->mFiles ) . " files checked, " .
58 - count( $this->mFailures ) . " failures found\n" );
 59+ count( $this->mFailures ) . " failures and " . count( $this->mWarnings ) .
 60+ " warnings found\n" );
5961 }
6062
6163 /**
@@ -133,6 +135,33 @@
134136 }
135137 return true;
136138 }
 139+
 140+ /**
 141+ * Check a file for non-fatal coding errors, such as byte-order marks in the beginning
 142+ * or pointless ?> closing tags at the end.
 143+ *
 144+ * @param $file String String Path to a file to check for errors
 145+ * @return boolean
 146+ */
 147+ private function checkForMistakes( $file ) {
 148+ $text = file_get_contents( $file );
 149+
 150+ $this->checkRegex( $file, $text, '/^[\s\r\n]+<\?/', 'leading whitespace' );
 151+ $this->checkRegex( $file, $text, '/\?>[\s\r\n]*$/', 'trailing ?>' );
 152+ $this->checkRegex( $file, $text, '/^[\xFF\xFE\xEF]/', 'byte-order mark' );
 153+ }
 154+
 155+ private function checkRegex( $file, $text, $regex, $desc ) {
 156+ if ( !preg_match( $regex, $text ) ) {
 157+ return;
 158+ }
 159+
 160+ if ( !isset( $this->mWarnings[$file] ) ) {
 161+ $this->mWarnings[$file] = array();
 162+ }
 163+ $this->mWarnings[$file][] = $desc;
 164+ $this->output( "Warning in file $file: $desc found.\n" );
 165+ }
137166 }
138167
139168 $maintClass = "SyntaxChecker";

Follow-up revisions

RevisionCommit summaryAuthorDate
r59053* Removed remaining trailing ?> from core....maxsem08:12, 14 November 2009

Status & tagging log