44
55use Clue \React \NDJson \Decoder ;
66use Clue \React \NDJson \Encoder ;
7+ use PHPStan \Analyser \AnalysedFilesResolver ;
78use PHPStan \Analyser \FileAnalyser ;
89use PHPStan \Analyser \InternalError ;
910use PHPStan \Analyser \NodeScopeResolver ;
2324use Symfony \Component \Console \Input \InputOption ;
2425use Symfony \Component \Console \Output \OutputInterface ;
2526use Throwable ;
26- use function array_fill_keys ;
2727use function array_merge ;
2828use function defined ;
2929use function is_array ;
@@ -124,17 +124,18 @@ protected function execute(InputInterface $input, OutputInterface $output): int
124124 $ nodeScopeResolver = $ container ->getByType (NodeScopeResolver::class);
125125 $ nodeScopeResolver ->setAnalysedFiles ($ analysedFiles );
126126
127- $ analysedFiles = array_fill_keys ($ analysedFiles , true );
127+ $ analyzedFilesResolver = new AnalysedFilesResolver ();
128+ $ analyzedFilesResolver ->setAnalysedFiles ($ analysedFiles );
128129
129130 $ tcpConnector = new TcpConnector ($ loop );
130- $ tcpConnector ->connect (sprintf ('127.0.0.1:%d ' , $ port ))->then (function (ConnectionInterface $ connection ) use ($ container , $ identifier , $ output , $ analysedFiles ): void {
131+ $ tcpConnector ->connect (sprintf ('127.0.0.1:%d ' , $ port ))->then (function (ConnectionInterface $ connection ) use ($ container , $ identifier , $ output , $ analyzedFilesResolver ): void {
131132 // phpcs:disable SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly
132133 $ jsonInvalidUtf8Ignore = defined ('JSON_INVALID_UTF8_IGNORE ' ) ? JSON_INVALID_UTF8_IGNORE : 0 ;
133134 // phpcs:enable
134135 $ out = new Encoder ($ connection , $ jsonInvalidUtf8Ignore );
135136 $ in = new Decoder ($ connection , true , 512 , $ jsonInvalidUtf8Ignore , $ container ->getParameter ('parallel ' )['buffer ' ]);
136137 $ out ->write (['action ' => 'hello ' , 'identifier ' => $ identifier ]);
137- $ this ->runWorker ($ container , $ out , $ in , $ output , $ analysedFiles );
138+ $ this ->runWorker ($ container , $ out , $ in , $ output , $ analyzedFilesResolver );
138139 });
139140
140141 $ loop ->run ();
@@ -146,15 +147,12 @@ protected function execute(InputInterface $input, OutputInterface $output): int
146147 return 0 ;
147148 }
148149
149- /**
150- * @param array<string, true> $analysedFiles
151- */
152150 private function runWorker (
153151 Container $ container ,
154152 WritableStreamInterface $ out ,
155153 ReadableStreamInterface $ in ,
156154 OutputInterface $ output ,
157- array $ analysedFiles ,
155+ AnalysedFilesResolver $ analysedFilesResolver ,
158156 ): void
159157 {
160158 $ handleError = function (Throwable $ error ) use ($ out , $ output ): void {
@@ -192,7 +190,7 @@ private function runWorker(
192190 $ fileAnalyser = $ container ->getByType (FileAnalyser::class);
193191 $ ruleRegistry = $ container ->getByType (RuleRegistry::class);
194192 $ collectorRegistry = $ container ->getByType (CollectorRegistry::class);
195- $ in ->on ('data ' , static function (array $ json ) use ($ fileAnalyser , $ ruleRegistry , $ collectorRegistry , $ out , $ analysedFiles ): void {
193+ $ in ->on ('data ' , static function (array $ json ) use ($ fileAnalyser , $ ruleRegistry , $ collectorRegistry , $ out , $ analysedFilesResolver ): void {
196194 $ action = $ json ['action ' ];
197195 if ($ action !== 'analyse ' ) {
198196 return ;
@@ -212,7 +210,7 @@ private function runWorker(
212210 $ exportedNodes = [];
213211 foreach ($ files as $ file ) {
214212 try {
215- $ fileAnalyserResult = $ fileAnalyser ->analyseFile ($ file , $ analysedFiles , $ ruleRegistry , $ collectorRegistry , null );
213+ $ fileAnalyserResult = $ fileAnalyser ->analyseFile ($ file , $ analysedFilesResolver , $ ruleRegistry , $ collectorRegistry , null );
216214 $ fileErrors = $ fileAnalyserResult ->getErrors ();
217215 $ filteredPhpErrors = array_merge ($ filteredPhpErrors , $ fileAnalyserResult ->getFilteredPhpErrors ());
218216 $ allPhpErrors = array_merge ($ allPhpErrors , $ fileAnalyserResult ->getAllPhpErrors ());
0 commit comments