Move up to date the parser test expectation.
[lhc/web/wiklou.git] / maintenance / checkSyntax.php
index cf1b262..02b5a69 100644 (file)
@@ -33,8 +33,8 @@ class CheckSyntax extends Maintenance {
                $this->mDescription = "Check syntax for all PHP files in MediaWiki";
                $this->addOption( 'with-extensions', 'Also recurse the extensions folder' );
                $this->addOption( 'path', 'Specific path (file or directory) to check, either with absolute path or relative to the root of this MediaWiki installation',
-                       false, true);
-               $this->addOption( 'list-file', 'Text file containing list of files or directories to check', false, true);
+                       false, true );
+               $this->addOption( 'list-file', 'Text file containing list of files or directories to check', false, true );
                $this->addOption( 'modified', 'Check only files that were modified (requires SVN command-line client)' );
                $this->addOption( 'syntax-only', 'Check for syntax validity only, skip code style warnings' );
        }
@@ -49,16 +49,16 @@ class CheckSyntax extends Maintenance {
                // ParseKit is broken on PHP 5.3+, disabled until this is fixed
                $useParseKit = function_exists( 'parsekit_compile_file' ) && version_compare( PHP_VERSION, '5.3', '<' );
 
-               $str = 'Checking syntax (using ' . ( $useParseKit ? 
-                       'parsekit)' : ' php -l, this can take a long time)' );
+               $str = 'Checking syntax (using ' . ( $useParseKit ?
+                       'parsekit' : ' php -l, this can take a long time' ) . ")\n";
                $this->output( $str );
-               foreach( $this->mFiles as $f ) {
-                       if( $useParseKit ) {
+               foreach ( $this->mFiles as $f ) {
+                       if ( $useParseKit ) {
                                $this->checkFileWithParsekit( $f );
                        } else {
                                $this->checkFileWithCli( $f );
                        }
-                       if( !$this->hasOption( 'syntax-only' ) ) {
+                       if ( !$this->hasOption( 'syntax-only' ) ) {
                                $this->checkForMistakes( $f );
                        }
                }
@@ -104,7 +104,7 @@ class CheckSyntax extends Maintenance {
                        if ( !$f ) {
                                $this->error( "Can't open file $file\n", true );
                        }
-                       while( $path = trim( fgets( $f ) ) ) {
+                       while ( $path = trim( fgets( $f ) ) ) {
                                $this->addPath( $path );
                        }
                        fclose( $f );
@@ -121,7 +121,7 @@ class CheckSyntax extends Maintenance {
 
                        preg_match_all( '/^\s*[AM].{7}(.*?)\r?$/m', $output, $matches );
                        foreach ( $matches[1] as $file ) {
-                               if ( self::isSuitableFile( $file ) && !is_dir( $file ) ) {
+                               if ( $this->isSuitableFile( $file ) && !is_dir( $file ) ) {
                                        $this->mFiles[] = $file;
                                }
                        }
@@ -132,18 +132,18 @@ class CheckSyntax extends Maintenance {
 
                // Only check files in these directories. 
                // Don't just put $IP, because the recursive dir thingie goes into all subdirs
-               $dirs = array( 
+               $dirs = array(
                        $IP . '/includes',
                        $IP . '/config',
                        $IP . '/languages',
                        $IP . '/maintenance',
                        $IP . '/skins',
                );
-               if( $this->hasOption( 'with-extensions' ) ) {
+               if ( $this->hasOption( 'with-extensions' ) ) {
                        $dirs[] = $IP . '/extensions';
                }
 
-               foreach( $dirs as $d ) {
+               foreach ( $dirs as $d ) {
                        $this->addDirectoryContent( $d );
                }
 
@@ -162,10 +162,11 @@ class CheckSyntax extends Maintenance {
         * Returns true if $file is of a type we can check
         */
        private function isSuitableFile( $file ) {
+               $file = str_replace( '\\', '/', $file );
                $ext = pathinfo( $file, PATHINFO_EXTENSION );
                if ( $ext != 'php' && $ext != 'inc' && $ext != 'php5' )
                        return false;
-               foreach( $this->mIgnorePaths as $regex ) {
+               foreach ( $this->mIgnorePaths as $regex ) {
                        $m = array();
                        if ( preg_match( "~{$regex}~", $file, $m ) )
                                return false;
@@ -202,7 +203,7 @@ class CheckSyntax extends Maintenance {
         */
        private function addDirectoryContent( $dir ) {
                $iterator = new RecursiveIteratorIterator(
-                       new RecursiveDirectoryIterator( $dir ), 
+                       new RecursiveDirectoryIterator( $dir ),
                        RecursiveIteratorIterator::SELF_FIRST
                );
                foreach ( $iterator as $file ) {
@@ -247,8 +248,8 @@ class CheckSyntax extends Maintenance {
         * @return boolean
         */
        private function checkFileWithCli( $file ) {
-               $res = exec( 'php -l ' . wfEscapeShellArg( $file ) ); 
-               if( strpos( $res, 'No syntax errors detected' ) === false ) {
+               $res = exec( 'php -l ' . wfEscapeShellArg( $file ) );
+               if ( strpos( $res, 'No syntax errors detected' ) === false ) {
                        $this->mFailures[$file] = $res;
                        $this->output( $res . "\n" );
                        return false;
@@ -264,7 +265,7 @@ class CheckSyntax extends Maintenance {
         * @return boolean
         */
        private function checkForMistakes( $file ) {
-               foreach( $this->mNoStyleCheckPaths as $regex ) {
+               foreach ( $this->mNoStyleCheckPaths as $regex ) {
                        $m = array();
                        if ( preg_match( "~{$regex}~", $file, $m ) )
                                return;