Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create QueryReflection lazily to prevent eager creation of a database connection #554

Merged
merged 2 commits into from
Feb 27, 2023

Conversation

staabm
Copy link
Owner

@staabm staabm commented Feb 27, 2023

prevents a exception while the rule is instantiated

$ vendor-bin/phpstan/vendor/bin/phpstan analyse -c deploy-phpstan.neon.dist --no-progress --debug
C:\dvl\Workspace\kunzmann\deploy.php
Uncaught staabm\PHPStanDba\DbaException: Reflector not initialized. Make sure a phpstan bootstrap file is configured which calls staabm\PHPStanDba\QueryReflection\QueryReflection::setupReflector(). in C:\dvl\Workspace\kunzmann\vendor-bin\phpstan\vendor\staabm\phpstan-dba\src\QueryReflection\QueryReflection.php:517
#0 C:\dvl\Workspace\kunzmann\vendor-bin\phpstan\vendor\staabm\phpstan-dba\src\QueryReflection\QueryReflection.php(66): staabm\PHPStanDba\QueryReflection\QueryReflection::reflector()
#1 C:\dvl\Workspace\kunzmann\vendor-bin\phpstan\vendor\staabm\phpstan-dba\src\Rules\DoctrineKeyValueStyleRule.php(58): staabm\PHPStanDba\QueryReflection\QueryReflection->__construct()
#2 C:\Users\mstaab\AppData\Local\Temp\phpstan\cache\nette.configurator\Container_0fd9d387b1.php(5547): staabm\PHPStanDba\Rules\DoctrineKeyValueStyleRule->__construct()
#3 phar://C:/dvl/Workspace/kunzmann/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/vendor/nette/di/src/DI/Container.php(162): Container_0fd9d387b1->createService0446()
#4 phar://C:/dvl/Workspace/kunzmann/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/vendor/nette/di/src/DI/Container.php(95): _PHPStan_8260032bc\Nette\DI\Container->createService()
#5 phar://C:/dvl/Workspace/kunzmann/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/src/DependencyInjection/Nette/NetteContainer.php(33): _PHPStan_8260032bc\Nette\DI\Container->getService()
#6 phar://C:/dvl/Workspace/kunzmann/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/src/DependencyInjection/Nette/NetteContainer.php(88): PHPStan\DependencyInjection\Nette\NetteContainer->getService()
#7 [internal function]: PHPStan\DependencyInjection\Nette\NetteContainer->PHPStan\DependencyInjection\Nette\{closure}()
#8 phar://C:/dvl/Workspace/kunzmann/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/src/DependencyInjection/Nette/NetteContainer.php(89): array_map()
#9 phar://C:/dvl/Workspace/kunzmann/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/src/DependencyInjection/Nette/NetteContainer.php(58): PHPStan\DependencyInjection\Nette\NetteContainer->tagsToServices()
#10 phar://C:/dvl/Workspace/kunzmann/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/src/DependencyInjection/MemoizingContainer.php(42): PHPStan\DependencyInjection\Nette\NetteContainer->getServicesByTag()
#11 phar://C:/dvl/Workspace/kunzmann/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/src/Rules/LazyRegistry.php(61): PHPStan\DependencyInjection\MemoizingContainer->getServicesByTag()
#12 phar://C:/dvl/Workspace/kunzmann/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/src/Rules/LazyRegistry.php(37): PHPStan\Rules\LazyRegistry->getRulesFromContainer()
#13 phar://C:/dvl/Workspace/kunzmann/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/FileAnalyser.php(104): PHPStan\Rules\LazyRegistry->getRules()
#14 phar://C:/dvl/Workspace/kunzmann/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/FileAnalyser.php(174): PHPStan\Analyser\FileAnalyser->PHPStan\Analyser\{closure}()
#15 phar://C:/dvl/Workspace/kunzmann/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/Analyser.php(72): PHPStan\Analyser\FileAnalyser->analyseFile()
#16 phar://C:/dvl/Workspace/kunzmann/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/src/Command/AnalyserRunner.php(62): PHPStan\Analyser\Analyser->analyse()
#17 phar://C:/dvl/Workspace/kunzmann/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/src/Command/AnalyseApplication.php(209): PHPStan\Command\AnalyserRunner->runAnalyser()
#18 phar://C:/dvl/Workspace/kunzmann/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/src/Command/AnalyseApplication.php(102): PHPStan\Command\AnalyseApplication->runAnalyser()
#19 phar://C:/dvl/Workspace/kunzmann/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/src/Command/AnalyseCommand.php(174): PHPStan\Command\AnalyseApplication->analyse()
#20 phar://C:/dvl/Workspace/kunzmann/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/vendor/symfony/console/Command/Command.php(259): PHPStan\Command\AnalyseCommand->execute()
#21 phar://C:/dvl/Workspace/kunzmann/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/vendor/symfony/console/Application.php(870): _PHPStan_8260032bc\Symfony\Component\Console\Command\Command->run()
#22 phar://C:/dvl/Workspace/kunzmann/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/vendor/symfony/console/Application.php(261): _PHPStan_8260032bc\Symfony\Component\Console\Application->doRunCommand()
#23 phar://C:/dvl/Workspace/kunzmann/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/vendor/symfony/console/Application.php(157): _PHPStan_8260032bc\Symfony\Component\Console\Application->doRun()
#24 phar://C:/dvl/Workspace/kunzmann/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/bin/phpstan(124): _PHPStan_8260032bc\Symfony\Component\Console\Application->run()
#25 phar://C:/dvl/Workspace/kunzmann/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/bin/phpstan(125): _PHPStan_8260032bc\{closure}()
#26 C:\dvl\Workspace\kunzmann\vendor-bin\phpstan\vendor\phpstan\phpstan\phpstan(8): require('...')
#27 C:\dvl\Workspace\kunzmann\vendor-bin\phpstan\vendor\bin\phpstan(120): include('...')
#28 {main}


@staabm staabm changed the title Create QueryReflection lazily to prevent eager creation of a database… Create QueryReflection lazily to prevent eager creation of a database connection Feb 27, 2023
@staabm staabm marked this pull request as ready for review February 27, 2023 08:48
@staabm
Copy link
Owner Author

staabm commented Feb 27, 2023

fyi @hemberger

@staabm staabm enabled auto-merge (squash) February 27, 2023 08:49
@staabm staabm merged commit 980fa40 into main Feb 27, 2023
@staabm staabm deleted the staabm-patch-3 branch February 27, 2023 08:52
@hemberger
Copy link
Contributor

Do you think we can make the SchemaReflection static in the QueryReflection class then? The reason I made QueryReflection a class property was to avoid recreating the SchemaReflection from scratch for each node we process. Or maybe there's a better way to avoid duplicating the queries that SchemaReflection performs?

@staabm
Copy link
Owner Author

staabm commented Feb 27, 2023

We could try moving QueryReflection and SchemaReflection into phpstan DI container

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants