77use Smeghead \PhpVariableHardUsage \Analyze \VariableAnalyzer ;
88use Smeghead \PhpVariableHardUsage \Parse \VariableParser ;
99
10- final class SingleCommand extends AbstractCommand
10+ class SingleCommand extends AbstractCommand
1111{
1212 private string $ filePath ;
1313
@@ -16,23 +16,29 @@ public function __construct(string $filePath)
1616 $ this ->filePath = $ filePath ;
1717 }
1818
19- public function execute (): void
19+ public function execute (): int
2020 {
2121 if (!file_exists ($ this ->filePath )) {
2222 fwrite (STDERR , "File not found: {$ this ->filePath }\n" );
23- return ;
23+ return 1 ;
2424 }
2525
2626 $ parser = new VariableParser ();
2727 $ content = file_get_contents ($ this ->filePath );
2828 if ($ content === false ) {
2929 fwrite (STDERR , "Failed to read file: {$ this ->filePath }\n" );
30- return ;
30+ return 1 ;
3131 }
3232
33- $ parseResult = $ parser ->parse ($ content );
34- $ analyzer = new VariableAnalyzer ($ this ->filePath , $ parseResult ->functions );
35- $ result = $ analyzer ->analyze ();
36- echo $ result ->format ();
33+ try {
34+ $ parseResult = $ parser ->parse ($ content );
35+ $ analyzer = new VariableAnalyzer ($ this ->filePath , $ parseResult ->functions );
36+ $ result = $ analyzer ->analyze ();
37+ echo $ result ->format ();
38+ return 0 ;
39+ } catch (\Exception $ e ) {
40+ fwrite (STDERR , "Error analyzing {$ this ->filePath }: {$ e ->getMessage ()}\n" );
41+ return 1 ;
42+ }
3743 }
3844}
0 commit comments