Documentation
[lhc/web/wiklou.git] / maintenance / checkSyntax.php
index bcde6a2..cc4e5af 100644 (file)
@@ -101,7 +101,9 @@ class CheckSyntax extends Maintenance {
                        return; // process only this path
                } elseif ( $this->hasOption( 'list-file' ) ) {
                        $file = $this->getOption( 'list-file' );
-                       $f = @fopen( $file, 'r' );
+                       wfSuppressWarnings();
+                       $f = fopen( $file, 'r' );
+                       wfRestoreWarnings();
                        if ( !$f ) {
                                $this->error( "Can't open file $file\n", true );
                        }
@@ -163,6 +165,8 @@ class CheckSyntax extends Maintenance {
 
        /**
         * Returns true if $file is of a type we can check
+        * @param $file string
+        * @return bool
         */
        private function isSuitableFile( $file ) {
                $file = str_replace( '\\', '/', $file );
@@ -179,6 +183,8 @@ class CheckSyntax extends Maintenance {
 
        /**
         * Add given path to file list, searching it in include path if needed
+        * @param $path string
+        * @return bool
         */
        private function addPath( $path ) {
                global $IP;
@@ -186,8 +192,10 @@ class CheckSyntax extends Maintenance {
        }
 
        /**
-       * Add given file to file list, or, if it's a directory, add its content
-       */
+        * Add given file to file list, or, if it's a directory, add its content
+        * @param $path string
+        * @return bool
+        */
        private function addFileOrDir( $path ) {
                if ( is_dir( $path ) ) {
                        $this->addDirectoryContent( $path );
@@ -275,7 +283,9 @@ class CheckSyntax extends Maintenance {
                }
 
                $text = file_get_contents( $file );
+               $tokens = token_get_all( $text );
 
+               $this->checkEvilToken( $file, $tokens, '@', 'Error supression operator (@)');
                $this->checkRegex( $file, $text, '/^[\s\r\n]+<\?/', 'leading whitespace' );
                $this->checkRegex( $file, $text, '/\?>[\s\r\n]*$/', 'trailing ?>' );
                $this->checkRegex( $file, $text, '/^[\xFF\xFE\xEF]/', 'byte-order mark' );
@@ -292,6 +302,18 @@ class CheckSyntax extends Maintenance {
                $this->mWarnings[$file][] = $desc;
                $this->output( "Warning in file $file: $desc found.\n" );
        }
+
+       private function checkEvilToken( $file, $tokens, $evilToken, $desc ) {
+               if ( !in_array( $evilToken, $tokens ) ) {
+                       return;
+               }
+
+               if ( !isset( $this->mWarnings[$file] ) ) {
+                       $this->mWarnings[$file] = array();
+               }
+               $this->mWarnings[$file][] = $desc;
+               $this->output( "Warning in file $file: $desc found.\n" );
+       }
 }
 
 $maintClass = "CheckSyntax";