Skip to content

Commit

Permalink
Merge pull request #24 from madewithlove/php8
Browse files Browse the repository at this point in the history
Bump minimum version to PHP 8
  • Loading branch information
WouterSioen authored Feb 10, 2021
2 parents 53837b3 + ec39792 commit 9e34e1d
Show file tree
Hide file tree
Showing 22 changed files with 75 additions and 196 deletions.
27 changes: 14 additions & 13 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,35 @@ jobs:
name: Psalm
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@master
- name: Psalm
uses: docker://vimeo/psalm-github-actions
- uses: actions/checkout@master
- uses: shivammathur/setup-php@master
with:
php-version: '8.0'
- name: Install dependencies
run: composer update
- name: Run Psalm
run: vendor/bin/psalm

phpunit:
runs-on: ubuntu-latest
strategy:
matrix:
php-versions: ['7.2', '7.3', '7.4']
steps:
- uses: actions/checkout@master
- uses: shivammathur/setup-php@v1
- uses: shivammathur/setup-php@master
with:
php-version: ${{ matrix.php-versions }}
php-version: '8.0'
- name: Install dependencies
run: composer install -n --prefer-dist
run: composer update
- name: Run PHPUnit unit tests
run: vendor/bin/phpunit

check-licenses:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: shivammathur/setup-php@v1
- uses: shivammathur/setup-php@master
with:
php-version: '7.4'
php-version: '8.0'
- name: Install dependencies
run: composer install -n --prefer-dist
run: composer update
- name: Run License Checker
run: bin/license-checker check
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
composer.phar
/vendor/
composer.lock
.phpunit.result.cache
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM php:cli-alpine
FROM php:8-cli-alpine

ENV COMPOSER_HOME /composer
ENV COMPOSER_ALLOW_SUPERUSER 1
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ pipeline to block merging when a non-verified license is being introduced to the

## Installation
Installing should be a breeze thanks to `composer`:
Note that you need PHP 8 to install the latest version (1.x).
If you are using an older version of PHP (7.x), older versions can be installed (0.x).

```
composer require madewithlove/license-checker
Expand Down
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@
"minimum-stability": "stable",
"bin": ["bin/license-checker"],
"require": {
"php": "^8.0",
"symfony/console": "^4.0 || ^5.0",
"symfony/process": "^4.0 || ^5.0",
"symfony/yaml": "^4.0 || ^5.0"
},
"require-dev": {
"phpunit/phpunit": "^8.5 || ^9.0",
"vimeo/psalm": "^3.9"
"phpunit/phpunit": "^9.5",
"vimeo/psalm": "^4.4"
},
"autoload": {
"psr-4": {
Expand Down
38 changes: 7 additions & 31 deletions src/Commands/CheckLicenses.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,50 +18,26 @@ class CheckLicenses extends Command
{
protected static $defaultName = 'check';

/**
* @var UsedLicensesParser
*/
private $usedLicenseParser;

/**
* @var AllowedLicensesParser
*/
private $allowedLicensesParser;

/**
* @var DependencyTree
*/
private $dependencyTree;

/**
* @var TableRenderer
*/
private $tableRenderer;

public function __construct(
UsedLicensesParser $usedLicensesParser,
AllowedLicensesParser $allowedLicensesParser,
DependencyTree $dependencyTree,
TableRenderer $tableRenderer
private UsedLicensesParser $usedLicensesParser,
private AllowedLicensesParser $allowedLicensesParser,
private DependencyTree $dependencyTree,
private TableRenderer $tableRenderer
) {
parent::__construct();
$this->usedLicenseParser = $usedLicensesParser;
$this->allowedLicensesParser = $allowedLicensesParser;
$this->dependencyTree = $dependencyTree;
$this->tableRenderer = $tableRenderer;
}

protected function configure(): void
{
$this->setDescription('Check licenses of composer dependencies');
}

protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);

try {
$usedLicenses = $this->usedLicenseParser->parseLicenses();
$usedLicenses = $this->usedLicensesParser->parseLicenses();
} catch (ProcessFailedException $e) {
$output->writeln($e->getMessage());
return 1;
Expand All @@ -81,7 +57,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
foreach ($dependencies as $dependency) {
$dependencyCheck = new DependencyCheck($dependency->getName());
foreach ($notAllowedLicenses as $notAllowedLicense) {
$packagesUsingThisLicense = $this->usedLicenseParser->getPackagesWithLicense($notAllowedLicense);
$packagesUsingThisLicense = $this->usedLicensesParser->getPackagesWithLicense($notAllowedLicense);
foreach ($packagesUsingThisLicense as $packageUsingThisLicense) {
if ($dependency->hasDependency($packageUsingThisLicense) || $dependency->getName() === $packageUsingThisLicense) {
$dependencyCheck = $dependencyCheck->addFailedDependency($packageUsingThisLicense, $notAllowedLicense);
Expand Down
11 changes: 2 additions & 9 deletions src/Commands/CountUsedLicenses.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace LicenseChecker\Commands;

use LicenseChecker\Composer\UsedLicensesParser;
use LicenseChecker\Composer\UsedLicensesRetriever;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
Expand All @@ -14,24 +13,18 @@ class CountUsedLicenses extends Command
{
protected static $defaultName = 'count';

/**
* @var UsedLicensesParser
*/
private $usedLicensesParser;

public function __construct(
UsedLicensesParser $usedLicensesParser
private UsedLicensesParser $usedLicensesParser
) {
parent::__construct();
$this->usedLicensesParser = $usedLicensesParser;
}

protected function configure(): void
{
$this->setDescription('Count number of dependencies for each license');
}

protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);
$rows = [];
Expand Down
18 changes: 3 additions & 15 deletions src/Commands/GenerateConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,19 @@ class GenerateConfig extends Command
{
protected static $defaultName = 'generate-config';

/**
* @var AllowedLicensesParser
*/
private $allowedLicensesParser;

/**
* @var UsedLicensesParser
*/
private $usedLicensesParser;

public function __construct(
AllowedLicensesParser $allowedLicensesParser,
UsedLicensesParser $usedLicensesParser
private AllowedLicensesParser $allowedLicensesParser,
private UsedLicensesParser $usedLicensesParser
) {
parent::__construct();
$this->allowedLicensesParser = $allowedLicensesParser;
$this->usedLicensesParser = $usedLicensesParser;
}

protected function configure(): void
{
$this->setDescription('Generates allowed licenses config based on used licenses');
}

protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);

Expand Down
14 changes: 4 additions & 10 deletions src/Commands/ListAllowedLicenses.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,18 @@ class ListAllowedLicenses extends Command
{
protected static $defaultName = 'allowed';

/**
* @var AllowedLicensesParser
*/
private $allowedLicensesParser;

public function __construct(AllowedLicensesParser $allowedLicensesParser)
{
public function __construct(
private AllowedLicensesParser $allowedLicensesParser
) {
parent::__construct();
$this->allowedLicensesParser = $allowedLicensesParser;
}


protected function configure(): void
{
$this->setDescription('List used licenses of composer dependencies');
}

protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): int
{
try {
$allowedLicenses = $this->allowedLicensesParser->getAllowedLicenses(getcwd());
Expand Down
10 changes: 2 additions & 8 deletions src/Commands/ListUsedLicenses.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,18 @@ class ListUsedLicenses extends Command
{
protected static $defaultName = 'used';

/**
* @var UsedLicensesParser
*/
private $usedLicensesParser;

public function __construct(
UsedLicensesParser $usedLicensesParser
private UsedLicensesParser $usedLicensesParser
) {
parent::__construct();
$this->usedLicensesParser = $usedLicensesParser;
}

protected function configure(): void
{
$this->setDescription('List used licenses of composer dependencies');
}

protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): int
{
try {
$usedLicenses = $this->usedLicensesParser->parseLicenses();
Expand Down
19 changes: 4 additions & 15 deletions src/Commands/Output/CauseOfFailure.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,10 @@

final class CauseOfFailure
{
/**
* @var string
*/
private $name;

/**
* @var string
*/
private $license;

public function __construct(string $name, string $license)
{
$this->name = $name;
$this->license = $license;
}
public function __construct(
private string $name,
private string $license
) {}

public function getName(): string
{
Expand Down
24 changes: 6 additions & 18 deletions src/Commands/Output/DependencyCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,18 @@

final class DependencyCheck
{
/**
* @var string
*/
private $name;

/**
* @var bool
*/
private $isAllowed = true;
private bool $isAllowed = true;

/**
* @var CauseOfFailure[]
*/
private $causedBy = [];
private array $causedBy = [];

/**
* @param string $name
*/
public function __construct(string $name)
{
$this->name = $name;
}
public function __construct(
private string $name
) {}

public function addFailedDependency($dependency, $license): self
public function addFailedDependency(string $dependency, string $license): self
{
$dependencyCheck = clone $this;
$dependencyCheck->isAllowed = false;
Expand Down
10 changes: 2 additions & 8 deletions src/Commands/Output/TableRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@ class TableRenderer
{
/**
* @param DependencyCheck[] $dependencyChecks
* @param SymfonyStyle $io
*/
public function renderDependencyChecks(array $dependencyChecks, SymfonyStyle $io)
public function renderDependencyChecks(array $dependencyChecks, SymfonyStyle $io): void
{
usort($dependencyChecks, function (DependencyCheck $dependencyCheck, DependencyCheck $other) {
usort($dependencyChecks, function (DependencyCheck $dependencyCheck, DependencyCheck $other): int {
return $dependencyCheck->isAllowed() <=> $other->isAllowed();
});

Expand All @@ -24,7 +23,6 @@ public function renderDependencyChecks(array $dependencyChecks, SymfonyStyle $io

/**
* @param DependencyCheck[] $dependencyChecks
* @return bool
*/
private function hasFailures(array $dependencyChecks): bool
{
Expand Down Expand Up @@ -103,7 +101,6 @@ private function renderAllOkay(array $dependencyChecks): array
}

/**
* @param DependencyCheck $dependencyCheck
* @return string[]
*/
private function renderAllowedLineWithEmptyFailureCause(DependencyCheck $dependencyCheck): array
Expand All @@ -116,8 +113,6 @@ private function renderAllowedLineWithEmptyFailureCause(DependencyCheck $depende
}

/**
* @param DependencyCheck $dependencyCheck
* @param CauseOfFailure $causeOfFailure
* @return string[]
*/
private function renderFailedLineWithCauseOfFailure(
Expand All @@ -132,7 +127,6 @@ private function renderFailedLineWithCauseOfFailure(
}

/**
* @param CauseOfFailure $causeOfFailure
* @return string[]
*/
private function renderAdditionalCauseOfFailure(CauseOfFailure $causeOfFailure): array
Expand Down
Loading

0 comments on commit 9e34e1d

Please sign in to comment.