|
5 | 5 | namespace Phauthentic\CognitiveCodeAnalysis\Business\Cognitive; |
6 | 6 |
|
7 | 7 | use Phauthentic\CognitiveCodeAnalysis\Business\Cognitive\Events\FileProcessed; |
| 8 | +use Phauthentic\CognitiveCodeAnalysis\Business\Cognitive\Events\ParserFailed; |
8 | 9 | use Phauthentic\CognitiveCodeAnalysis\Business\Cognitive\Events\SourceFilesFound; |
9 | 10 | use Phauthentic\CognitiveCodeAnalysis\Business\DirectoryScanner; |
10 | 11 | use Phauthentic\CognitiveCodeAnalysis\CognitiveAnalysisException; |
|
13 | 14 | use SplFileInfo; |
14 | 15 | use Symfony\Component\Messenger\Exception\ExceptionInterface; |
15 | 16 | use Symfony\Component\Messenger\MessageBusInterface; |
| 17 | +use Throwable; |
16 | 18 |
|
17 | 19 | /** |
18 | 20 | * CognitiveMetricsCollector class that collects cognitive metrics from source files |
@@ -69,16 +71,24 @@ private function getCodeFromFile(SplFileInfo $file): string |
69 | 71 | * |
70 | 72 | * @param iterable<SplFileInfo> $files |
71 | 73 | * @return CognitiveMetricsCollection |
72 | | - * @throws CognitiveAnalysisException|ExceptionInterface |
| 74 | + * @throws ExceptionInterface |
73 | 75 | */ |
74 | 76 | private function findMetrics(iterable $files): CognitiveMetricsCollection |
75 | 77 | { |
76 | 78 | $metricsCollection = new CognitiveMetricsCollection(); |
77 | 79 |
|
78 | 80 | foreach ($files as $file) { |
79 | | - $metrics = $this->parser->parse( |
80 | | - $this->getCodeFromFile($file) |
81 | | - ); |
| 81 | + try { |
| 82 | + $metrics = $this->parser->parse( |
| 83 | + $this->getCodeFromFile($file) |
| 84 | + ); |
| 85 | + } catch (Throwable $exception) { |
| 86 | + $this->messageBus->dispatch(new ParserFailed( |
| 87 | + $file, |
| 88 | + $exception |
| 89 | + )); |
| 90 | + continue; |
| 91 | + } |
82 | 92 |
|
83 | 93 | $metricsCollection = $this->processMethodMetrics( |
84 | 94 | $metrics, |
|
0 commit comments