Making WordPress.org


Ignore:
Timestamp:
07/30/2020 04:34:54 AM (6 years ago)
Author:
tellyworth
Message:

Plugin dir: catch PHP syntax errors when checking block plugins.

See #5303.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/cli/class-block-plugin-checker.php

    r10102 r10104  
    342342        public static function find_called_functions_in_file($file) {
    343343                $source = file_get_contents($file);
    344                 $tokens = token_get_all($source, TOKEN_PARSE);
     344                try {
     345                        $tokens = token_get_all($source, TOKEN_PARSE);
     346                } catch( \Error $e ) {
     347                        return new \WP_Error( 'php_error', $e->getMessage(), $e->getLine() );
     348                }
    345349
    346350                $function_calls = array();
     
    375379                foreach ( Filesystem::list_files( $base_dir, true, '!\.php$!i' ) as $filename ) {
    376380                        $php_calls = self::find_called_functions_in_file( $filename );
    377                         $all_calls += $php_calls;
     381                        if ( is_wp_error( $php_calls ) ) {
     382                                $this->record_result(
     383                                        __FUNCTION__,
     384                                        'error',
     385                                        sprintf(
     386                                                __( 'PHP error %s in %s', 'wporg-plugins' ),
     387                                                $php_calls->get_error_message(),
     388                                                sprintf( '<a href="%s">%s</a>',
     389                                                        $this->get_browser_url( $filename ) . '#L' . $php_calls->get_error_data(),
     390                                                        $this->relative_filename( $filename )
     391                                                )
     392                                        ),
     393                                        [ $filename, $php_calls->get_error_data() ]
     394                                );
     395                        } else {
     396                                $all_calls += $php_calls;
     397                        }
    378398                }
    379399
Note: See TracChangeset for help on using the changeset viewer.