From 69ef704c75230dbe74d7362212942f26ce889835 Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Wed, 5 May 2021 00:41:58 +0100 Subject: [PATCH 1/5] Update Setup PHP action --- .github/workflows/main.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index d335c47..c07af7a 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -25,7 +25,7 @@ jobs: name: PHP ${{ matrix.php }} / ${{ matrix.deps }} steps: - uses: actions/checkout@v2 - - uses: shivammathur/setup-php@151d1849c224dd5757287959c3c93f9e748f24d1 + - uses: shivammathur/setup-php@4067ce8b814db5bfc731c8906aa3034f28911e9f with: php-version: ${{ matrix.php }} - name: Cache dependencies @@ -59,7 +59,7 @@ jobs: name: PHP 5.3 steps: - uses: actions/checkout@v2 - - uses: shivammathur/setup-php@151d1849c224dd5757287959c3c93f9e748f24d1 + - uses: shivammathur/setup-php@4067ce8b814db5bfc731c8906aa3034f28911e9f with: php-version: 5.3 - name: Parse ComposerPlugin.php From ba71035e7f4b172eafd4203bf8d3b3d6b2e12326 Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Wed, 5 May 2021 00:42:24 +0100 Subject: [PATCH 2/5] Test on PHP 8 --- .github/workflows/main.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index c07af7a..aa8b2b3 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -18,6 +18,7 @@ jobs: - '7.2' - '7.3' - '7.4' + - '8.0' deps: - highest - lowest From 2ec95cff3b8aaa09dfa224c0f810ca9daab984f3 Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Wed, 5 May 2021 00:55:16 +0100 Subject: [PATCH 3/5] Improve PHP 5.3 check --- .github/workflows/main.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index aa8b2b3..12ba2c8 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -67,3 +67,8 @@ jobs: run: php -l src/ComposerPlugin.php - name: Parse ComposerPlugin.fake.php run: php -l src/ComposerPlugin.fake.php + - name: Integration test + run: | + composer global config repositories.0 path "$(pwd)" + composer global require cs278/composer-audit '*@dev' + composer global audit -vvv From 7b297f6d82e1f5a9be8f561fc86781eb47cec6ae Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Wed, 5 May 2021 01:06:56 +0100 Subject: [PATCH 4/5] Improve experience for non compatible PHP versions --- .github/workflows/main.yml | 13 ++++++++- src/AuditNotCompatibleCommand.php | 46 +++++++++++++++++++++++++++++++ src/ComposerPlugin.fake.php | 18 +++++++++++- 3 files changed, 75 insertions(+), 2 deletions(-) create mode 100644 src/AuditNotCompatibleCommand.php diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 12ba2c8..98fb922 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -67,8 +67,19 @@ jobs: run: php -l src/ComposerPlugin.php - name: Parse ComposerPlugin.fake.php run: php -l src/ComposerPlugin.fake.php + - name: Parse AuditNotCompatibleCommand.php + run: php -l src/AuditNotCompatibleCommand.php - name: Integration test run: | composer global config repositories.0 path "$(pwd)" - composer global require cs278/composer-audit '*@dev' + composer global require --ignore-platform-reqs cs278/composer-audit '*@dev' + + set +e composer global audit -vvv + result=$? + set -e + + if [ $result -ne 2 ]; then + echo "Expected audit command to exit with error code 2, got: ${result}" >&2 + exit 1 + fi diff --git a/src/AuditNotCompatibleCommand.php b/src/AuditNotCompatibleCommand.php new file mode 100644 index 0000000..4bd0f8b --- /dev/null +++ b/src/AuditNotCompatibleCommand.php @@ -0,0 +1,46 @@ +setName('audit'); + $this->setDescription('Check packages for security advisories.'); + $this->addOption( + 'no-dev', + null, + InputOption::VALUE_NONE, + 'Disable checking of development dependencies.' + ); + $this->addOption( + 'update', + null, + InputOption::VALUE_NONE, + 'Update security advisory information if a new version is available.' + ); + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + $output = $output instanceof ConsoleOutputInterface ? $output->getErrorOutput() : $output; + + $output->writeln(sprintf('Composer Audit is not compatible with PHP %s', PHP_VERSION)); + + return 2; + } +} diff --git a/src/ComposerPlugin.fake.php b/src/ComposerPlugin.fake.php index 927f1d0..ad20066 100644 --- a/src/ComposerPlugin.fake.php +++ b/src/ComposerPlugin.fake.php @@ -4,6 +4,8 @@ use Composer\Composer; use Composer\IO\IOInterface; +use Composer\Plugin\Capability\CommandProvider as CommandProviderCapability; +use Composer\Plugin\Capable; use Composer\Plugin\PluginInterface; /** @@ -11,7 +13,7 @@ * * @internal This class is used when loading the plugin with PHP < 7.1. */ -final class ComposerPlugin implements PluginInterface +final class ComposerPlugin implements PluginInterface, Capable, CommandProviderCapability { public function activate(Composer $composer, IOInterface $io) { @@ -27,4 +29,18 @@ public function uninstall(Composer $composer, IOInterface $io) { } + + public function getCapabilities() + { + return array( + 'Composer\\Plugin\\Capability\\CommandProvider' => \get_class($this), + ); + } + + public function getCommands() + { + return array( + new AuditNotCompatibleCommand(), + ); + } } From 1ecc0cb71f39ce40e432d70658e20e3dd6296589 Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Wed, 5 May 2021 01:25:01 +0100 Subject: [PATCH 5/5] Move legacy PHP code in to it's own directory --- .github/workflows/main.yml | 11 ++--- composer.json | 2 +- src/ComposerPlugin.fake.php | 46 ------------------- src/ComposerPlugin.php | 36 +++++++++++++-- src/ComposerPlugin.real.php | 37 --------------- .../AuditNotCompatibleCommand.php | 2 +- src/Legacy/CommandProvider.php | 18 ++++++++ src/Legacy/ComposerPlugin.php | 44 ++++++++++++++++++ src/Legacy/README | 2 + 9 files changed, 102 insertions(+), 96 deletions(-) delete mode 100644 src/ComposerPlugin.fake.php delete mode 100644 src/ComposerPlugin.real.php rename src/{ => Legacy}/AuditNotCompatibleCommand.php (97%) create mode 100644 src/Legacy/CommandProvider.php create mode 100644 src/Legacy/ComposerPlugin.php create mode 100644 src/Legacy/README diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 98fb922..6acbbc3 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -63,12 +63,11 @@ jobs: - uses: shivammathur/setup-php@4067ce8b814db5bfc731c8906aa3034f28911e9f with: php-version: 5.3 - - name: Parse ComposerPlugin.php - run: php -l src/ComposerPlugin.php - - name: Parse ComposerPlugin.fake.php - run: php -l src/ComposerPlugin.fake.php - - name: Parse AuditNotCompatibleCommand.php - run: php -l src/AuditNotCompatibleCommand.php + - name: Syntax check + run: | + while read file; do + php -l "$file" + done < <(find src/Legacy -type f -name "*.php") - name: Integration test run: | composer global config repositories.0 path "$(pwd)" diff --git a/composer.json b/composer.json index 2eb3e54..07786dd 100644 --- a/composer.json +++ b/composer.json @@ -32,6 +32,6 @@ "sort-packages": true }, "extra": { - "class": "Cs278\\ComposerAudit\\ComposerPlugin" + "class": "Cs278\\ComposerAudit\\Legacy\\ComposerPlugin" } } diff --git a/src/ComposerPlugin.fake.php b/src/ComposerPlugin.fake.php deleted file mode 100644 index ad20066..0000000 --- a/src/ComposerPlugin.fake.php +++ /dev/null @@ -1,46 +0,0 @@ - \get_class($this), - ); - } - - public function getCommands() - { - return array( - new AuditNotCompatibleCommand(), - ); - } -} diff --git a/src/ComposerPlugin.php b/src/ComposerPlugin.php index 1048abc..5530670 100644 --- a/src/ComposerPlugin.php +++ b/src/ComposerPlugin.php @@ -2,10 +2,36 @@ namespace Cs278\ComposerAudit; -if (!class_exists(__NAMESPACE__.'\\ComposerPlugin', false)) { - if (\PHP_VERSION_ID >= 70100) { - require __DIR__.'/ComposerPlugin.real.php'; - } else { - require __DIR__.'/ComposerPlugin.fake.php'; +use Composer\Composer; +use Composer\IO\IOInterface; +use Composer\Plugin\PluginInterface; +use Composer\Plugin\Capable; +use Composer\Plugin\Capability\CommandProvider as CommandProviderCapability; + +/** + * Composer Audit Plugin declaration. + */ +final class ComposerPlugin implements PluginInterface, Capable +{ + public function activate(Composer $composer, IOInterface $io) + { + + } + + public function deactivate(Composer $composer, IOInterface $io) + { + + } + + public function uninstall(Composer $composer, IOInterface $io) + { + + } + + public function getCapabilities() + { + return [ + CommandProviderCapability::class => CommandProvider::class, + ]; } } diff --git a/src/ComposerPlugin.real.php b/src/ComposerPlugin.real.php deleted file mode 100644 index 5530670..0000000 --- a/src/ComposerPlugin.real.php +++ /dev/null @@ -1,37 +0,0 @@ - CommandProvider::class, - ]; - } -} diff --git a/src/AuditNotCompatibleCommand.php b/src/Legacy/AuditNotCompatibleCommand.php similarity index 97% rename from src/AuditNotCompatibleCommand.php rename to src/Legacy/AuditNotCompatibleCommand.php index 4bd0f8b..f7488c3 100644 --- a/src/AuditNotCompatibleCommand.php +++ b/src/Legacy/AuditNotCompatibleCommand.php @@ -1,6 +1,6 @@ = 70100) { + \class_alias(substr(__NAMESPACE__, 0, strrpos(__NAMESPACE__, '\\')).'\\ComposerPlugin', __NAMESPACE__.'\\ComposerPlugin'); + } else { + /** + * Composer Audit Plugin declaration. + * + * @internal This class is used when loading the plugin with PHP < 7.1. + */ + final class ComposerPlugin implements PluginInterface, Capable + { + public function activate(Composer $composer, IOInterface $io) + { + + } + + public function deactivate(Composer $composer, IOInterface $io) + { + + } + + public function uninstall(Composer $composer, IOInterface $io) + { + + } + + public function getCapabilities() + { + return array( + 'Composer\\Plugin\\Capability\\CommandProvider' => __NAMESPACE__.'\\CommandProvider', + ); + } + } + } +} diff --git a/src/Legacy/README b/src/Legacy/README new file mode 100644 index 0000000..22f42be --- /dev/null +++ b/src/Legacy/README @@ -0,0 +1,2 @@ +Code in this namespace must be compatible with the lowest PHP version that +Composer supports.