Skip to content

feat: propagate config.platform from core's composer.json#24

Open
mstrelan wants to merge 3 commits into
amateescu:mainfrom
mstrelan:main
Open

feat: propagate config.platform from core's composer.json#24
mstrelan wants to merge 3 commits into
amateescu:mainfrom
mstrelan:main

Conversation

@mstrelan

@mstrelan mstrelan commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

This aims to solve https://www.drupal.org/project/drupal/issues/3605599 without waiting for core.

Disclaimer - this is entirely vibe coded.

Below is the description that Claude came up with, which is an accurate summary of what I'm trying to do:

composer-merge-plugin does not merge the config section, only package metadata. This means config.platform.php from core's composer.json is not visible to tools like PHPStan when running via composer.local.json as the root, causing PHPStan to analyse against the running PHP version (e.g. 8.5) instead of the declared target version (e.g. 8.3 on 11.x).

Hoist the core composer.json read out of the installer-paths block and propagate config.platform via Config::merge() alongside it, using the same pattern already used for installer-paths and root version pinning.

I ran some tests on main, as well as 11.x and 11.4.x but it wasn't working, so I had Claude fix it:

The original plugin approach (in-memory Config::merge() only) was insufficient — phpstan reads $COMPOSER env var, finds composer.local.json, and reads config.platform directly from that file in its own process. The fix adds syncPlatformToRootFile() which writes config.platform from composer.json into composer.local.json on disk during every composer invocation. Branch switches work correctly as long as you run ddev composer update after switching, which you need to do anyway.

So now if you switch branch and run ddev composer update it will sync config.platform.php from core in to composer.local.json so phpstan detects it. You can see the output by adding -vvv to the phpstan command:

PHP runtime version: 8.5.5
PHP version for analysis: 8.3 (from config.platform.php in composer.json)

I've also added a bats test to verify.

mstrelan added 3 commits June 23, 2026 16:36
composer-merge-plugin does not merge the config section, only package
metadata. This means config.platform.php from core's composer.json is
not visible to tools like PHPStan when running via composer.local.json
as the root, causing PHPStan to analyse against the running PHP version
(e.g. 8.5) instead of the declared target version (e.g. 8.3 on 11.x).

Hoist the core composer.json read out of the installer-paths block and
propagate config.platform via Config::merge() alongside it, using the
same pattern already used for installer-paths and root version pinning.
PHPStan reads platform.php directly from the file pointed to by the
$COMPOSER env var (e.g. composer.local.json) in a separate process.
The in-memory Config::merge() is not visible to it.

Add syncPlatformToRootFile() which writes config.platform from
composer.json into composer.local.json on disk whenever the two differ,
so PHPStan (and any other tool that reads the root file directly) picks
up the correct platform PHP version without needing a phpVersion setting
in phpstan.neon.
Assert that after composer install:
- config.platform.php in composer.local.json matches the value from
  core's composer.json
- PHPStan reports the platform version for analysis rather than
  falling back to the runtime PHP version
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.

1 participant