diff --git a/CHANGELOG.md b/CHANGELOG.md index 37934a1..c9e8755 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,11 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p ## [Unreleased] +## [v1.1.0] - 2024-11-21 +### Added + +- Add `eol'ed PHP version` usage check. + ## [v1.0.8] - 2024-05-14 ### Fixed @@ -59,8 +64,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p - Initial release. -[Unreleased]: https://github.com/raphaelstolt/package-analyser/compare/v1.0.8...HEAD +[Unreleased]: https://github.com/raphaelstolt/package-analyser/compare/v1.1.0...HEAD +[v1.1.0]: https://github.com/raphaelstolt/package-analyser/compare/v1.0.8...v1.1.0 [v1.0.8]: https://github.com/raphaelstolt/package-analyser/compare/v1.0.7...v1.0.8 [v1.0.7]: https://github.com/raphaelstolt/package-analyser/compare/v1.0.6...v1.0.7 [v1.0.6]: https://github.com/raphaelstolt/package-analyser/compare/v1.0.5...v1.0.6 diff --git a/app/Commands/Analyse.php b/app/Commands/Analyse.php index 5520e01..1caa490 100644 --- a/app/Commands/Analyse.php +++ b/app/Commands/Analyse.php @@ -76,7 +76,8 @@ public function handle(): int $this->packageAnalyser->getStepsForTable()[14], $this->packageAnalyser->getStepsForTable()[15], $this->packageAnalyser->getStepsForTable()[16], - new TableSeparator(), + $this->packageAnalyser->getStepsForTable()[17], + new TableSeparator, [new TableCell('Ran '.$amountOfAnalysisSteps.' analysis steps. '.$violationText, ['colspan' => 3])], ]); diff --git a/app/Domain/PackageAnalyser.php b/app/Domain/PackageAnalyser.php index bf8ea2c..2138aa6 100644 --- a/app/Domain/PackageAnalyser.php +++ b/app/Domain/PackageAnalyser.php @@ -46,6 +46,7 @@ public function __construct(readonly string $directoryToAnalyse) ['id' => 'cli-binary', 'summary' => 'Put CLI/TUI binaries in a /bin directory in the base directory of the package.', 'status' => ViolationStatus::Irrelevant], ['id' => 'cli-phar', 'summary' => 'Distribute CLI/TUI binaries via PHAR.', 'status' => ViolationStatus::Irrelevant], ['id' => 'composer-scripts', 'summary' => 'Utilise Composer scripts.', 'status' => ViolationStatus::False], + ['id' => 'eol-php', 'summary' => 'Use a supported PHP version.', 'status' => ViolationStatus::False], ]; $this->stepIds = Arr::pluck($this->steps, 'id'); @@ -125,6 +126,9 @@ public function analyse(): int case 'composer-scripts': $this->alternateStepStatus('composer-scripts', $this->checkComposerScriptsExistence()); break; + case 'eol-php': + $this->alternateStepStatus('eol-php', $this->checkComposerPHPVersion()); + break; } } @@ -133,7 +137,7 @@ public function analyse(): int private function checkTestsDirectoryExistence(): ViolationStatus { - $finder = new Finder(); + $finder = new Finder; if ($finder->depth(0)->directories()->name(['test*', 'spec*'])->in($this->directoryToAnalyse)->hasResults()) { return ViolationStatus::True; } @@ -160,7 +164,7 @@ private function checkTestingToolExistence(): ViolationStatus private function checkChangelogExistence(): ViolationStatus { - $finder = new Finder(); + $finder = new Finder; if ($finder->depth(0)->files()->name('CHANGELOG*')->in($this->directoryToAnalyse)->hasResults()) { return ViolationStatus::True; } @@ -170,7 +174,7 @@ private function checkChangelogExistence(): ViolationStatus private function checkReadmeExistence(): ViolationStatus { - $finder = new Finder(); + $finder = new Finder; if ($finder->depth(0)->files()->name('README*')->in($this->directoryToAnalyse)->hasResults()) { return ViolationStatus::True; } @@ -180,7 +184,7 @@ private function checkReadmeExistence(): ViolationStatus private function checkLicenseExistence(): ViolationStatus { - $finder = new Finder(); + $finder = new Finder; if ($finder->depth(0)->files()->name('LICENSE*')->in($this->directoryToAnalyse)->hasResults()) { return ViolationStatus::True; } @@ -224,14 +228,14 @@ private function checkStaticAnalysisToolExistence(): ViolationStatus private function checkCiUsage(): ViolationStatus { - $finder = new Finder(); + $finder = new Finder; $finder->ignoreDotFiles(false); if ($finder->depth(1)->path('.github/workflows')->in($this->directoryToAnalyse)->hasResults()) { return ViolationStatus::True; } - $finder = new Finder(); + $finder = new Finder; $finder->ignoreDotFiles(false); if ($finder->depth(0)->files()->name('.gitlab-ci*')->in($this->directoryToAnalyse)->hasResults()) { @@ -243,7 +247,7 @@ private function checkCiUsage(): ViolationStatus private function checkGitattributesExistence(): ViolationStatus { - $finder = new Finder(); + $finder = new Finder; $finder->ignoreDotFiles(false); if ($finder->depth(0)->files()->name('.gitattributes')->in($this->directoryToAnalyse)->hasResults()) { @@ -255,7 +259,7 @@ private function checkGitattributesExistence(): ViolationStatus private function checkGitignoreExistence(): ViolationStatus { - $finder = new Finder(); + $finder = new Finder; $finder->ignoreDotFiles(false); if ($finder->depth(0)->files()->name('.gitignore')->in($this->directoryToAnalyse)->hasResults()) { @@ -267,7 +271,7 @@ private function checkGitignoreExistence(): ViolationStatus private function checkSrcOrAppExistence(): ViolationStatus { - $finder = new Finder(); + $finder = new Finder; if ($finder->depth(0)->path(['app', 'src'])->in($this->directoryToAnalyse)->hasResults()) { return ViolationStatus::True; @@ -305,7 +309,7 @@ private function checkSemanticVersioningUsage(): ViolationStatus private function checkVcsExistence(): ViolationStatus { - $finder = new Finder(); + $finder = new Finder; $finder->ignoreDotFiles(false); $finder->ignoreVCS(false); @@ -347,7 +351,7 @@ private function checkCliBinaryDirectoryExistence(): ViolationStatus } if ($this->isACliOrTui) { - $finder = new Finder(); + $finder = new Finder; if ($finder->depth(0)->path('bin')->in($this->directoryToAnalyse)->hasResults()) { $this->alternateStepStatus('cli-binary', ViolationStatus::True); @@ -380,7 +384,7 @@ private function checkPharConfigurationExistence(): ViolationStatus } if ($this->isACliOrTui) { - $finder = new Finder(); + $finder = new Finder; if ($finder->depth(0)->files()->name('box.json*')->in($this->directoryToAnalyse)->hasResults()) { return ViolationStatus::True; @@ -399,7 +403,7 @@ private function checkPharConfigurationExistence(): ViolationStatus private function checkComposerScriptsExistence(): ViolationStatus { if ($this->isAPhpPackage() === ViolationStatus::True) { - $composerJson = json_decode(file_get_contents('composer.json'), true); + $composerJson = json_decode(file_get_contents($this->directoryToAnalyse.DIRECTORY_SEPARATOR.'composer.json'), true); if (isset($composerJson['scripts'])) { if (count($composerJson['scripts']) > 0) { @@ -413,6 +417,25 @@ private function checkComposerScriptsExistence(): ViolationStatus return ViolationStatus::False; } + private function checkComposerPHPVersion(): ViolationStatus + { + $latestSupportedPHPVersion = 8.1; + + if ($this->isAPhpPackage() === ViolationStatus::True) { + $composerJson = json_decode(file_get_contents($this->directoryToAnalyse.DIRECTORY_SEPARATOR.'composer.json'), true); + + if (isset($composerJson['require']['php'])) { + if (floatval(str_replace(['^', '~', '>='], '', $composerJson['require']['php'])) >= floatval($latestSupportedPHPVersion)) { + return ViolationStatus::True; + } + } + + return ViolationStatus::False; + } + + return ViolationStatus::False; + } + public function getSteps(): array { return $this->steps; diff --git a/app/Exceptions/NonExistentPackageDirectory.php b/app/Exceptions/NonExistentPackageDirectory.php index 6c9ea73..2ea3c59 100644 --- a/app/Exceptions/NonExistentPackageDirectory.php +++ b/app/Exceptions/NonExistentPackageDirectory.php @@ -2,6 +2,4 @@ namespace App\Exceptions; -class NonExistentPackageDirectory extends \Exception -{ -} +class NonExistentPackageDirectory extends \Exception {} diff --git a/app/Exceptions/NonExistentStepId.php b/app/Exceptions/NonExistentStepId.php index b634b9c..9fa7c83 100644 --- a/app/Exceptions/NonExistentStepId.php +++ b/app/Exceptions/NonExistentStepId.php @@ -2,6 +2,4 @@ namespace App\Exceptions; -class NonExistentStepId extends \Exception -{ -} +class NonExistentStepId extends \Exception {} diff --git a/composer.json b/composer.json index ba0df42..a995da3 100644 --- a/composer.json +++ b/composer.json @@ -16,7 +16,7 @@ "nunomaduro/termwind": "^2.0" }, "require-dev": { - "laravel/pint": "^1.15", + "laravel/pint": "^1.17", "mockery/mockery": "^1.6", "pestphp/pest": "^2.22", "stolt/lean-package-validator": "^4.0.0" diff --git a/tests/Feature/AnalyseCommandTest.php b/tests/Feature/AnalyseCommandTest.php index 76ff408..faf4d5e 100644 --- a/tests/Feature/AnalyseCommandTest.php +++ b/tests/Feature/AnalyseCommandTest.php @@ -15,7 +15,7 @@ }); it('prints number of analysis steps', function () { - $this->artisan('analyse '.$this->temporaryDirectory)->expectsOutputToContain('Ran 17 analysis steps'); + $this->artisan('analyse '.$this->temporaryDirectory)->expectsOutputToContain('Ran 18 analysis steps'); }); it('has success emoji for successful analyse step', function () { diff --git a/tests/Pest.php b/tests/Pest.php index a7fa826..501d59e 100644 --- a/tests/Pest.php +++ b/tests/Pest.php @@ -17,7 +17,7 @@ $this->temporaryDirectory = setUpTemporaryDirectory(); exec('cd '.$this->temporaryDirectory.' && git init 2>&1'); })->afterEach(function () { - $filesystem = new Filesystem(); + $filesystem = new Filesystem; $filesystem->deleteDirectory($this->temporaryDirectory); })->in('Feature');