r55298 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r55297‎ | r55298 | r55299 >
Date:00:46, 19 August 2009
Author:demon
Status:ok
Tags:
Comment:
Redo r54644. php -l still sucks, but some people don't have parsekit. So let's support both :)
Modified paths:
  • /trunk/phase3/maintenance/syntaxChecker.php (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/syntaxChecker.php
@@ -43,7 +43,15 @@
4444 $this->output( "done.\n" );
4545
4646 $this->output( "Checking syntax (this can take a really long time)...\n\n" );
47 - $res = $this->checkSyntax();
 47+ foreach( $this->mFiles as $f ) {
 48+ if( function_exists( 'parsekit_compile_file' ) ) {
 49+ $this->checkFileWithParsekit( $f );
 50+ } else {
 51+ $this->checkFileWithCli( $f );
 52+ }
 53+ }
 54+ $this->output( "\nDone! " . count( $this->mFiles ) . " files checked, " .
 55+ count( $this->mFailures ) . " failures found" );
4856 }
4957
5058 /**
@@ -80,21 +88,50 @@
8189 }
8290
8391 /**
84 - * Check the files for syntax errors
 92+ * Check a file for syntax errors using Parsekit. Shamelessly stolen
 93+ * from tools/lint.php by TimStarling
 94+ * @param $file String Path to a file to check for syntax errors
8595 * @return boolean
8696 */
87 - private function checkSyntax() {
88 - foreach( $this->mFiles as $f ) {
89 - $res = exec( 'php -l ' . $f );
90 - if( strpos( $res, 'No syntax errors detected' ) === false ) {
91 - $this->mFailures[] = $f;
92 - $this->error( $res . "\n" );
 97+ private function checkFileWithParsekit( $file ) {
 98+ static $okErrors = array(
 99+ 'Redefining already defined constructor',
 100+ 'Assigning the return value of new by reference is deprecated',
 101+ );
 102+ $errors = array();
 103+ parsekit_compile_file( $file, $errors, PARSEKIT_SIMPLE );
 104+ $ret = true;
 105+ if ( $errors ) {
 106+ foreach ( $errors as $error ) {
 107+ foreach ( $okErrors as $okError ) {
 108+ if ( substr( $error['errstr'], 0, strlen( $okError ) ) == $okError ) {
 109+ continue 2;
 110+ }
 111+ }
 112+ $ret = false;
 113+ $this->output( "Error in $file line {$error['lineno']}: {$error['errstr']}\n" );
 114+ $this->mFailures[$file] = $errors;
93115 }
94116 }
95 - $this->output( count($this->mFiles) . " files checked, "
96 - . count($this->mFailures) . " failures\n" );
 117+ return $ret;
97118 }
 119+
 120+ /**
 121+ * Check a file for syntax errors using php -l
 122+ * @param $file String Path to a file to check for syntax errors
 123+ * @return boolean
 124+ */
 125+ private function checkFileWithCli( $file ) {
 126+ $res = exec( 'php -l ' . $file );
 127+ if( strpos( $res, 'No syntax errors detected' ) === false ) {
 128+ $this->mFailures[$file] = $res;
 129+ $this->output( $res . "\n" );
 130+ return false;
 131+ }
 132+ return true;
 133+ }
98134 }
99135
100136 $maintClass = "SyntaxChecker";
101137 require_once( DO_MAINTENANCE );
 138+

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r54644Use parsekit instead. php -l sucks.demon23:13, 8 August 2009

Status & tagging log