diff --git a/src/Command/WorkerCommand.php b/src/Command/WorkerCommand.php index e51aaa0d6b..e9a3042abe 100644 --- a/src/Command/WorkerCommand.php +++ b/src/Command/WorkerCommand.php @@ -103,6 +103,11 @@ protected function execute(InputInterface $input, OutputInterface $output): int $loop = new StreamSelectLoop(); $container = $inceptionResult->getContainer(); + + /** @var NodeScopeResolver $nodeScopeResolver */ + $nodeScopeResolver = $container->getByType(NodeScopeResolver::class); + $nodeScopeResolver->setAnalysedFiles($inceptionResult->getFiles()); + $tcpConector = new TcpConnector($loop); $tcpConector->connect(sprintf('127.0.0.1:%d', $port))->then(function (ConnectionInterface $connection) use ($container, $identifier): void { $out = new Encoder($connection); @@ -138,11 +143,8 @@ private function runWorker(Container $container, WritableStreamInterface $out, R /** @var Registry $registry */ $registry = $container->getByType(Registry::class); - /** @var NodeScopeResolver $nodeScopeResolver */ - $nodeScopeResolver = $container->getByType(NodeScopeResolver::class); - // todo collectErrors (from Analyser) - $in->on('data', static function (array $json) use ($fileAnalyser, $registry, $nodeScopeResolver, $out): void { + $in->on('data', static function (array $json) use ($fileAnalyser, $registry, $out): void { $action = $json['action']; if ($action !== 'analyse') { return; @@ -150,7 +152,6 @@ private function runWorker(Container $container, WritableStreamInterface $out, R $internalErrorsCount = 0; $files = $json['files']; - $nodeScopeResolver->setAnalysedFiles($files); $errors = []; $inferrablePropertyTypesFromConstructorHelper = new InferrablePropertyTypesFromConstructorHelper(); foreach ($files as $file) { diff --git a/tests/PHPStan/Parallel/ParallelAnalyserIntegrationTest.php b/tests/PHPStan/Parallel/ParallelAnalyserIntegrationTest.php new file mode 100644 index 0000000000..1c99f25c68 --- /dev/null +++ b/tests/PHPStan/Parallel/ParallelAnalyserIntegrationTest.php @@ -0,0 +1,63 @@ +assertJsonStringEqualsJsonString(Json::encode([ + 'totals' => [ + 'errors' => 0, + 'file_errors' => 3, + ], + 'files' => [ + sprintf('%s/data/trait-definition.php (in context of class ParallelAnalyserIntegrationTest\\Bar)', __DIR__) => [ + 'errors' => 1, + 'messages' => [ + [ + 'message' => 'Method ParallelAnalyserIntegrationTest\\Bar::doFoo() has no return typehint specified.', + 'line' => 8, + 'ignorable' => true, + ], + ], + ], + sprintf('%s/data/trait-definition.php (in context of class ParallelAnalyserIntegrationTest\\Foo)', __DIR__) => [ + 'errors' => 2, + 'messages' => [ + [ + 'message' => 'Method ParallelAnalyserIntegrationTest\\Foo::doFoo() has no return typehint specified.', + 'line' => 8, + 'ignorable' => true, + ], + [ + 'message' => 'Access to an undefined property ParallelAnalyserIntegrationTest\\Foo::$test.', + 'line' => 10, + 'ignorable' => true, + ], + ], + ], + ], + 'errors' => [], + ]), $output); + $this->assertSame(1, $exitCode); + } + +} diff --git a/tests/PHPStan/Parallel/data/trait-definition.php b/tests/PHPStan/Parallel/data/trait-definition.php new file mode 100644 index 0000000000..edf01e73f8 --- /dev/null +++ b/tests/PHPStan/Parallel/data/trait-definition.php @@ -0,0 +1,13 @@ +test = 1; + } + +} diff --git a/tests/PHPStan/Parallel/data/traits.php b/tests/PHPStan/Parallel/data/traits.php new file mode 100644 index 0000000000..402a344dd5 --- /dev/null +++ b/tests/PHPStan/Parallel/data/traits.php @@ -0,0 +1,20 @@ +