Skip to content

Commit

Permalink
Merge pull request #10 from cs278/php8
Browse files Browse the repository at this point in the history
PHP 8
  • Loading branch information
cs278 authored May 5, 2021
2 parents 980292a + 1ecc0cb commit 16b402f
Show file tree
Hide file tree
Showing 9 changed files with 164 additions and 79 deletions.
28 changes: 22 additions & 6 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@ jobs:
- '7.2'
- '7.3'
- '7.4'
- '8.0'
deps:
- highest
- lowest
fail-fast: true
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
Expand Down Expand Up @@ -59,10 +60,25 @@ 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
run: php -l src/ComposerPlugin.php
- name: Parse ComposerPlugin.fake.php
run: php -l src/ComposerPlugin.fake.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)"
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
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@
"sort-packages": true
},
"extra": {
"class": "Cs278\\ComposerAudit\\ComposerPlugin"
"class": "Cs278\\ComposerAudit\\Legacy\\ComposerPlugin"
}
}
30 changes: 0 additions & 30 deletions src/ComposerPlugin.fake.php

This file was deleted.

36 changes: 31 additions & 5 deletions src/ComposerPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
];
}
}
37 changes: 0 additions & 37 deletions src/ComposerPlugin.real.php

This file was deleted.

46 changes: 46 additions & 0 deletions src/Legacy/AuditNotCompatibleCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

namespace Cs278\ComposerAudit\Legacy;

use Composer\Command\BaseCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\ConsoleOutputInterface;
use Symfony\Component\Console\Output\OutputInterface;

/**
* Dummy command which tells the user they are using an unsupported PHP.
*
* @copyright 2021 Chris Smith
* @license MIT
*/
final class AuditNotCompatibleCommand extends BaseCommand
{
protected function configure()
{
// Configuration is copied from AuditCommand so that the command accepts the same inputs.
$this->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('<error>Composer Audit is not compatible with PHP %s', PHP_VERSION));

return 2;
}
}
18 changes: 18 additions & 0 deletions src/Legacy/CommandProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace Cs278\ComposerAudit\Legacy;

use Composer\Plugin\Capability\CommandProvider as CommandProviderCapability;

/**
* @internal This class is used when loading the plugin with PHP < 7.1.
*/
final class CommandProvider implements CommandProviderCapability
{
public function getCommands()
{
return array(
new AuditNotCompatibleCommand(),
);
}
}
44 changes: 44 additions & 0 deletions src/Legacy/ComposerPlugin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

namespace Cs278\ComposerAudit\Legacy;

use Composer\Composer;
use Composer\IO\IOInterface;
use Composer\Plugin\Capable;
use Composer\Plugin\PluginInterface;

if (!class_exists(__NAMESPACE__.'\\ComposerPlugin', false)) {
if (\PHP_VERSION_ID >= 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',
);
}
}
}
}
2 changes: 2 additions & 0 deletions src/Legacy/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Code in this namespace must be compatible with the lowest PHP version that
Composer supports.

0 comments on commit 16b402f

Please sign in to comment.