Skip to content

Commit

Permalink
Adds check for eoled PHP versions
Browse files Browse the repository at this point in the history
  • Loading branch information
raphaelstolt committed Nov 21, 2024
1 parent ceab606 commit 73b63da
Show file tree
Hide file tree
Showing 9 changed files with 479 additions and 463 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion app/Commands/Analyse.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 <info>'.$amountOfAnalysisSteps.'</info> analysis steps. '.$violationText, ['colspan' => 3])],
]);

Expand Down
49 changes: 36 additions & 13 deletions app/Domain/PackageAnalyser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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;
}
}

Expand All @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand Down Expand Up @@ -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()) {
Expand All @@ -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()) {
Expand All @@ -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()) {
Expand All @@ -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;
Expand Down Expand Up @@ -305,7 +309,7 @@ private function checkSemanticVersioningUsage(): ViolationStatus

private function checkVcsExistence(): ViolationStatus
{
$finder = new Finder();
$finder = new Finder;
$finder->ignoreDotFiles(false);
$finder->ignoreVCS(false);

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -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) {
Expand All @@ -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;
Expand Down
4 changes: 1 addition & 3 deletions app/Exceptions/NonExistentPackageDirectory.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,4 @@

namespace App\Exceptions;

class NonExistentPackageDirectory extends \Exception
{
}
class NonExistentPackageDirectory extends \Exception {}
4 changes: 1 addition & 3 deletions app/Exceptions/NonExistentStepId.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,4 @@

namespace App\Exceptions;

class NonExistentStepId extends \Exception
{
}
class NonExistentStepId extends \Exception {}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Loading

0 comments on commit 73b63da

Please sign in to comment.