Index: trunk/phase3/maintenance/syntaxChecker.php |
— | — | @@ -34,12 +34,20 @@ |
35 | 35 | } |
36 | 36 | |
37 | 37 | public function execute() { |
| 38 | + if( !function_exists( 'parsekit_compile_file' ) ) { |
| 39 | + $this->error( 'Requires PHP with parsekit', true ); |
| 40 | + } |
| 41 | + |
38 | 42 | $this->output( "Building file list..." ); |
39 | 43 | $this->buildFileList(); |
40 | 44 | $this->output( "done.\n" ); |
41 | 45 | |
42 | 46 | $this->output( "Checking syntax (this can take a really long time)...\n\n" ); |
43 | | - $res = $this->checkSyntax(); |
| 47 | + foreach( $this->mFiles as $f ) { |
| 48 | + $this->checkFile( $f ); |
| 49 | + } |
| 50 | + $this->output( "\nDone! " . count( $this->mFiles ) . " files checked, " . |
| 51 | + count( $this->mFailures ) . " failures found" ); |
44 | 52 | } |
45 | 53 | |
46 | 54 | /** |
— | — | @@ -76,18 +84,32 @@ |
77 | 85 | } |
78 | 86 | |
79 | 87 | /** |
80 | | - * Check the files for syntax errors |
| 88 | + * Check a file for syntax errors. Shamelessly stolen |
| 89 | + * from tools/lint.php by TimStarling |
| 90 | + * |
| 91 | + * @param $file String Path to a file to check for syntax errors |
81 | 92 | */ |
82 | | - private function checkSyntax() { |
83 | | - foreach( $this->mFiles as $f ) { |
84 | | - $res = exec( 'php -l ' . $f ); |
85 | | - if( strpos( $res, 'No syntax errors detected' ) === false ) { |
86 | | - $this->mFailures[] = $f; |
87 | | - $this->error( $res . "\n" ); |
| 93 | + private function checkFile( $file ) { |
| 94 | + static $okErrors = array( |
| 95 | + 'Redefining already defined constructor', |
| 96 | + 'Assigning the return value of new by reference is deprecated', |
| 97 | + ); |
| 98 | + $errors = array(); |
| 99 | + parsekit_compile_file( $file, $errors, PARSEKIT_SIMPLE ); |
| 100 | + $ret = true; |
| 101 | + if ( $errors ) { |
| 102 | + foreach ( $errors as $error ) { |
| 103 | + foreach ( $okErrors as $okError ) { |
| 104 | + if ( substr( $error['errstr'], 0, strlen( $okError ) ) == $okError ) { |
| 105 | + continue 2; |
| 106 | + } |
| 107 | + } |
| 108 | + $ret = false; |
| 109 | + $this->output( "Error in $file line {$error['lineno']}: {$error['errstr']}\n" ); |
88 | 110 | } |
| 111 | + $this->mFailures[ $file ] = $errors; |
89 | 112 | } |
90 | | - $this->output( count($this->mFiles) . " files checked, " |
91 | | - . count($this->mFailures) . " failures\n" ); |
| 113 | + return $ret; |
92 | 114 | } |
93 | 115 | } |
94 | 116 | |