feat(plugins): add preserve_autoload option for PHP plugin configuration#2744
Draft
sinemacula-ben wants to merge 2 commits intoqltysh:mainfrom
Draft
feat(plugins): add preserve_autoload option for PHP plugin configuration#2744sinemacula-ben wants to merge 2 commits intoqltysh:mainfrom
sinemacula-ben wants to merge 2 commits intoqltysh:mainfrom
Conversation
|
|
When PHP linter extensions like Larastan bootstrap the Laravel application, they need the project's PSR-4 namespace mappings in the sandbox autoloader. Previously, filter_composer unconditionally stripped autoload/autoload-dev sections, causing "Class not found" crashes. This adds a preserve_autoload boolean (default false) that, when enabled, preserves autoload sections and creates symlinks from the sandbox to the project root so Composer's generated autoloader resolves paths to the actual source files.
dac181b to
03d6eef
Compare
Contributor
1 new issue
|
02c2f7b to
208c1c8
Compare
Extract collect_psr_paths and collect_string_array_paths helpers to address qlty nested-control-flow and function-complexity findings.
208c1c8 to
fd37bad
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
preserve_autoloadboolean option to plugin configuration (defaults tofalse, preserving existing behavior)autoload/autoload-devsections in the sandbox'scomposer.jsonand creates symlinks from the sandbox to the workspace root so Composer's generated autoloader resolves PSR-4/classmap/files paths to actual project source filesworkspace_root(serde-skipped) toPluginDefso symlinks target the correct project root even whenpackage_filelives in a subdirectory like.qlty/configs/preserve_autoload = truerequirespackage_fileto be setProblem
filter_composerunconditionally stripsautoload/autoload-devfrom the user'scomposer.jsonbefore installing in the sandbox. This prevents PHPStan extensions like Larastan from working — Larastan bootstraps the Laravel application at startup and needs the project's PSR-4 namespace mappings (e.g.,App\→app/) in the sandbox autoloader. Without them, Larastan crashes withClass "App\..." not found.Solution
The symlink approach was chosen as the least invasive fix:
preserve_autoload = truekeeps autoload sections in the filteredcomposer.jsoncomposer update, symlinks are created from{sandbox}/{path}→{workspace_root}/{path}for each autoload path$baseDir(the sandbox) to resolve paths — symlinks make these paths validcomposer updateso Composer's classmap scanner can also find classesUsage
Files changed
qlty-config/src/config/plugin.rspreserve_autoloadfield onPluginDefandEnabledPlugin,workspace_rootfield onPluginDef, validationqlty-check/src/planner/config.rspreserve_autoloadandworkspace_rootfrom config to runtimeqlty-check/src/tool/php/composer.rscreate_autoload_symlinks,collect_autoload_paths, platform-specificcreate_symlink, testsTest plan
test_filter_composer— existing behavior unchanged (autoload stripped by default)test_filter_composer_no_filter— existing behavior unchangedtest_filter_composer_preserve_autoload— autoload retained when flag is settest_collect_autoload_paths— all Composer autoload types extracted (psr-4, psr-0, classmap, files)test_collect_autoload_paths_empty— no autoload sections returns emptytest_collect_autoload_paths_skips_empty_strings— root namespace mapping ("") skippedtest_create_autoload_symlinks— symlinks created from sandbox to workspace root (composer.json in subdirectory)test_create_autoload_symlinks_skips_when_disabled— no symlinks when preserve_autoload is falsetest_create_autoload_symlinks_skips_nonexistent_targets— missing source directories gracefully skippedtest_enabled_plugin_validate_success_with_preserve_autoload_and_package_file— valid config acceptedtest_enabled_plugin_validate_failure_with_preserve_autoload_but_no_package_file— invalid config rejectedtest_update_existing_composer_json,test_lock_file_*tests still pass