Skip to content

Commit

Permalink
Use original exceptions where possible.
Browse files Browse the repository at this point in the history
  • Loading branch information
johnbillion committed Nov 30, 2024
1 parent 684a9b1 commit f32a24f
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions generate.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,20 +67,20 @@
}
}

try {
// Parse the PHP file
$contents = file_get_contents( $file );
// Parse the PHP file
$contents = file_get_contents( $file );

if ( $contents === false ) {
throw new \Exception( 'Failed to read file ' . $file );
}
if ( $contents === false ) {
throw new \Exception( 'Failed to read file ' . $file );
}

$stmts = $parser->parse( $contents );
$stmts = $parser->parse( $contents );

if ( ! is_array( $stmts ) ) {
throw new \Exception( 'Failed to parse file ' . $file );
}
if ( ! is_array( $stmts ) ) {
throw new \Exception( 'Failed to parse file ' . $file );
}

try {
// Find all function and method nodes
// Create a new FindingVisitor instance
$visitor = new FindingVisitor(
Expand Down Expand Up @@ -171,8 +171,7 @@
}
} catch ( Error $e ) {
// Handle parsing errors
echo 'Error parsing file: ', $e->getMessage();
exit( 1 );
throw new \Exception( 'Error parsing file: ' . $e->getMessage() );
}
}
}
Expand All @@ -188,6 +187,12 @@
);
$json = json_encode( $data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES );

file_put_contents( $output_file, $json );
$written = file_put_contents( $output_file, $json );

if ( $written === false ) {
echo '❌ Failed to write symbols to symbols.json.' . PHP_EOL;
exit( 1 );
}

echo '✅ Symbols written to symbols.json.' . PHP_EOL;

echo 'Done.' . PHP_EOL;

0 comments on commit f32a24f

Please sign in to comment.