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

Prefix dependencies with PHP-Scoper #879

Draft
wants to merge 30 commits into
base: trunk
Choose a base branch
from
Draft

Conversation

swissspidy
Copy link
Member

@swissspidy swissspidy commented Feb 25, 2025

All the production dependencies required by Plugin Check are prefixed and stored in vendor-prefixed. This includes:

  • afragen/wordpress-plugin-readme-parser
  • plugin-check/phpcs-sniffs
  • squizlabs/php_codesniffer

This avoids any autoloading conflicts in case another plugin uses the same dependencies.

The plugin's own classes are autoloaded with a new slim autoloader in includes/vendor. No actual dependencies are in there, it's just a classmap.

For afragen/wordpress-plugin-readme-parser there is a special case: if the plugin is running on WordPress.org, the original and unprefixed WordPressdotorg\Plugin_Directory\Readme\Parser is available, so there is a class_exists check to use that one if available.

Unfortunately right now requires dependencies to be prefixed manually by installing PHP-Scoper in that other directory & running composer prefix-dependencies

Fixes #328

@swissspidy swissspidy added [Type] Enhancement A suggestion for improvement of an existing feature Infrastructure Issues for the overall plugin infrastructure labels Feb 25, 2025
@swissspidy
Copy link
Member Author

@ernilambar FWIW the issue is that the latest PHP-Scoper requires PHP 8.2. This could be mitigated by installing that dependency with PHP 8.2 separate from the others, run the prefixing, then downgrade again.

@swissspidy
Copy link
Member Author

@ernilambar I think it's very close now, after having fixed most of the namespace/autoloader issues. The last one seems to be specifically Fatal error: Cannot declare class WordPress\Plugin_Check\Vendor\WordPressVIPMinimum\Sniffs\Sniff, because the name is already in use in /var/www/html/wp-content/plugins/plugin-check/vendor-prefixed/vendor/automattic/vipwpcs/WordPressVIPMinimum/Sniffs/Sniff.php in unit tests. Probably the same thing that also causes some Behat failures.

Don't yet know why because it doesn't really happen to me locally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Infrastructure Issues for the overall plugin infrastructure [Type] Enhancement A suggestion for improvement of an existing feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Prefix Composer dependencies
2 participants