Merge "Align "What's this" vertically"
[lhc/web/wiklou.git] / maintenance / checkSyntax.php
index 4821e04..3910f29 100644 (file)
@@ -31,8 +31,8 @@ require_once __DIR__ . '/Maintenance.php';
 class CheckSyntax extends Maintenance {
 
        // List of files we're going to check
-       private $mFiles = array(), $mFailures = array(), $mWarnings = array();
-       private $mIgnorePaths = array(), $mNoStyleCheckPaths = array();
+       private $mFiles = [], $mFailures = [], $mWarnings = [];
+       private $mIgnorePaths = [], $mNoStyleCheckPaths = [];
 
        public function __construct() {
                parent::__construct();
@@ -65,19 +65,9 @@ class CheckSyntax extends Maintenance {
        public function execute() {
                $this->buildFileList();
 
-               // 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' ) . ")\n";
-               $this->output( $str );
+               $this->output( "Checking syntax (using php -l, this can take a long time)\n" );
                foreach ( $this->mFiles as $f ) {
-                       if ( $useParseKit ) {
-                               $this->checkFileWithParsekit( $f );
-                       } else {
-                               $this->checkFileWithCli( $f );
-                       }
+                       $this->checkFileWithCli( $f );
                        if ( !$this->hasOption( 'syntax-only' ) ) {
                                $this->checkForMistakes( $f );
                        }
@@ -93,12 +83,10 @@ class CheckSyntax extends Maintenance {
        private function buildFileList() {
                global $IP;
 
-               $this->mIgnorePaths = array(
-                       // Compat stuff, explodes on PHP 5.3
-                       "includes/NamespaceCompat.php$",
-               );
+               $this->mIgnorePaths = [
+               ];
 
-               $this->mNoStyleCheckPaths = array(
+               $this->mNoStyleCheckPaths = [
                        // Third-party code we don't care about
                        "/activemq_stomp/",
                        "EmailPage/PHPMailer",
@@ -110,7 +98,7 @@ class CheckSyntax extends Maintenance {
                        "QPoll/Excel/",
                        "/geshi/",
                        "/smarty/",
-               );
+               ];
 
                if ( $this->hasOption( 'path' ) ) {
                        $path = $this->getOption( 'path' );
@@ -151,13 +139,13 @@ 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 = [
                        $IP . '/includes',
                        $IP . '/mw-config',
                        $IP . '/languages',
                        $IP . '/maintenance',
                        $IP . '/skins',
-               );
+               ];
                if ( $this->hasOption( 'with-extensions' ) ) {
                        $dirs[] = $IP . '/extensions';
                }
@@ -180,7 +168,6 @@ class CheckSyntax extends Maintenance {
         * @return array Resulting list of changed files
         */
        private function getGitModifiedFiles( $path ) {
-
                global $wgMaxShellMemory;
 
                if ( !is_dir( "$path/.git" ) ) {
@@ -215,7 +202,7 @@ class CheckSyntax extends Maintenance {
 
                $wgMaxShellMemory = $oldMaxShellMemory;
 
-               $arr = array();
+               $arr = [];
                $filename = strtok( $output, "\n" );
                while ( $filename !== false ) {
                        if ( $filename !== '' ) {
@@ -239,7 +226,7 @@ class CheckSyntax extends Maintenance {
                        return false;
                }
                foreach ( $this->mIgnorePaths as $regex ) {
-                       $m = array();
+                       $m = [];
                        if ( preg_match( "~{$regex}~", $file, $m ) ) {
                                return false;
                        }
@@ -293,36 +280,6 @@ class CheckSyntax extends Maintenance {
                }
        }
 
-       /**
-        * Check a file for syntax errors using Parsekit. Shamelessly stolen
-        * from tools/lint.php by TimStarling
-        * @param string $file Path to a file to check for syntax errors
-        * @return bool
-        */
-       private function checkFileWithParsekit( $file ) {
-               static $okErrors = array(
-                       'Redefining already defined constructor',
-                       'Assigning the return value of new by reference is deprecated',
-               );
-               $errors = array();
-               parsekit_compile_file( $file, $errors, PARSEKIT_SIMPLE );
-               $ret = true;
-               if ( $errors ) {
-                       foreach ( $errors as $error ) {
-                               foreach ( $okErrors as $okError ) {
-                                       if ( substr( $error['errstr'], 0, strlen( $okError ) ) == $okError ) {
-                                               continue 2;
-                                       }
-                               }
-                               $ret = false;
-                               $this->output( "Error in $file line {$error['lineno']}: {$error['errstr']}\n" );
-                               $this->mFailures[$file] = $errors;
-                       }
-               }
-
-               return $ret;
-       }
-
        /**
         * Check a file for syntax errors using php -l
         * @param string $file Path to a file to check for syntax errors
@@ -348,7 +305,7 @@ class CheckSyntax extends Maintenance {
         */
        private function checkForMistakes( $file ) {
                foreach ( $this->mNoStyleCheckPaths as $regex ) {
-                       $m = array();
+                       $m = [];
                        if ( preg_match( "~{$regex}~", $file, $m ) ) {
                                return;
                        }
@@ -369,7 +326,7 @@ class CheckSyntax extends Maintenance {
                }
 
                if ( !isset( $this->mWarnings[$file] ) ) {
-                       $this->mWarnings[$file] = array();
+                       $this->mWarnings[$file] = [];
                }
                $this->mWarnings[$file][] = $desc;
                $this->output( "Warning in file $file: $desc found.\n" );
@@ -381,7 +338,7 @@ class CheckSyntax extends Maintenance {
                }
 
                if ( !isset( $this->mWarnings[$file] ) ) {
-                       $this->mWarnings[$file] = array();
+                       $this->mWarnings[$file] = [];
                }
                $this->mWarnings[$file][] = $desc;
                $this->output( "Warning in file $file: $desc found.\n" );