phpstan / extension-installer

Composer plugin for automatic installation of PHPStan extensions.
MIT License
399 stars 27 forks source link

Allow plugin to be called from script #30

Closed ruudk closed 3 years ago

ruudk commented 3 years ago

By changing Plugin::process method to static we can call it from a Composer script. Same approach as here: https://github.com/composer/package-versions-deprecated/blob/master/src/PackageVersions/Installer.php#L146

This is ideal for situations where you want to are using composer install --no-scripts but do want to install the PHPStan extensions. In my case composer automatically clears the cache which takes a lot of time on our CI (big project).

You can add a script to your own composer.json:

    "scripts": {
        "install-phpstan-extensions": "PHPStan\\ExtensionInstaller\\Plugin::process"
    }

And then run composer run install-phpstan-extensions to install the extensions:

$ composer run install-phpstan-extensions
> PHPStan\ExtensionInstaller\Plugin::process
phpstan/extension-installer: Extensions installed

Without this change, it's also possible, but it generates a deprecation notice:

$ composer run install-phpstan-extensions
> PHPStan\ExtensionInstaller\Plugin::process
Deprecation Notice: Non-static method PHPStan\ExtensionInstaller\Plugin::process() should not be called statically in phar:///usr/local/Cellar/composer/2.0.9/bin/composer/src/Composer/EventDispatcher/EventDispatcher.php:324
phpstan/extension-installer: Extensions installed
ondrejmirtes commented 3 years ago

Hi, what I'd like more, is:

1) Create a new static method generateConfig 2) Move all the logic from process there. 3) Call self::generateConfig() from process.

Also would be nice to cover this scenario in .github/workflows/integration-tests.yml.

ruudk commented 3 years ago

Thanks for the feedback.

I've actually worked around the problem by making sure the cache:clear step can be disabled, while the rest would still work.

As I'm not going to use this feature, I'd rather close the PR.