Index: trunk/phase3/maintenance/syntaxChecker.php |
— | — | @@ -43,7 +43,15 @@ |
44 | 44 | $this->output( "done.\n" ); |
45 | 45 | |
46 | 46 | $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" ); |
48 | 56 | } |
49 | 57 | |
50 | 58 | /** |
— | — | @@ -80,21 +88,50 @@ |
81 | 89 | } |
82 | 90 | |
83 | 91 | /** |
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 |
85 | 95 | * @return boolean |
86 | 96 | */ |
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; |
93 | 115 | } |
94 | 116 | } |
95 | | - $this->output( count($this->mFiles) . " files checked, " |
96 | | - . count($this->mFailures) . " failures\n" ); |
| 117 | + return $ret; |
97 | 118 | } |
| 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 | + } |
98 | 134 | } |
99 | 135 | |
100 | 136 | $maintClass = "SyntaxChecker"; |
101 | 137 | require_once( DO_MAINTENANCE ); |
| 138 | + |