Author: Shivam Mathur (shivammathur)
Date: 2026-04-02T06:38:37+05:30
Commit: Refactor Helper::rmdirr to a static method · php/web-downloads@a328788 · GitHub
Raw diff: https://github.com/php/web-downloads/commit/a328788f0c5d9430ca70c325754221450d9f3cbd.diff
Refactor Helper::rmdirr to a static method
Changed paths:
M src/Actions/GetArtifacts.php
M src/Console/Command/PhpCommand.php
M src/Console/Command/WinlibsCommand.php
M src/Helpers/Helpers.php
M tests/Actions/GetArtifactsTest.php
M tests/Actions/GetListingTest.php
M tests/Actions/UpdateReleasesJsonTest.php
M tests/Console/Command/PeclCommandTest.php
M tests/Console/Command/PhpCommandTest.php
M tests/Console/Command/SeriesDeleteCommandTest.php
M tests/Console/Command/SeriesInitCommandTest.php
M tests/Console/Command/SeriesStabilityCommandTest.php
M tests/Console/Command/SeriesUpdateCommandTest.php
M tests/Console/Command/WinlibsCommandTest.php
M tests/Helpers/HelpersTest.php
M tests/Http/Controllers/DeletePendingJobControllerTest.php
M tests/Http/Controllers/SeriesUpdateControllerTest.php
Diff:
diff --git a/src/Actions/GetArtifacts.php b/src/Actions/GetArtifacts.php
index 5167e00..217246d 100644
--- a/src/Actions/GetArtifacts.php
+++ b/src/Actions/GetArtifacts.php
@@ -36,7 +36,7 @@ public function handle($workflow_run_id, #[\SensitiveParameter] $token): void
$artifacts = json_decode($response, true);
$workflowRunDirectory = getenv('BUILDS_DIRECTORY') . "/winlibs/" . $workflow_run_id;
if (is_dir($workflowRunDirectory)) {
- (new Helpers)->rmdirr($workflowRunDirectory);
+ Helpers::rmdirr($workflowRunDirectory);
}
umask(0);
mkdir($workflowRunDirectory, 0777, true);
diff --git a/src/Console/Command/PhpCommand.php b/src/Console/Command/PhpCommand.php
index ea82c62..5ba935c 100644
--- a/src/Console/Command/PhpCommand.php
+++ b/src/Console/Command/PhpCommand.php
@@ -60,7 +60,7 @@ public function handle(): int
$tempDirectory = "/tmp/php-" . $hash;
if (is_dir($tempDirectory)) {
- (new Helpers)->rmdirr($tempDirectory);
+ Helpers::rmdirr($tempDirectory);
}
mkdir($tempDirectory, 0755, true);
@@ -87,7 +87,7 @@ public function handle(): int
$this->updateLatestBuilds($releases, $destinationDirectory);
}
- (new Helpers)->rmdirr($tempDirectory);
+ Helpers::rmdirr($tempDirectory);
unlink($filepath . '.lock');
}
@@ -97,7 +97,7 @@ public function handle(): int
$tempDirectories = glob('/tmp/php-*');
if($tempDirectories) {
foreach ($tempDirectories as $tempDirectory) {
- (new Helpers)->rmdirr($tempDirectory);
+ Helpers::rmdirr($tempDirectory);
}
}
return Command::FAILURE;
@@ -132,7 +132,7 @@ private function moveBuild(string $tempDirectory, string $destinationDirectory):
$destination = $destinationDirectory . '/' . $fileName;
rename($file, $destination);
}
- (new Helpers)->rmdirr($tempDirectory);
+ Helpers::rmdirr($tempDirectory);
$this->copyBuildsToArchive($destinationDirectory, $version);
} else {
throw new Exception('No builds found in the artifact');
diff --git a/src/Console/Command/WinlibsCommand.php b/src/Console/Command/WinlibsCommand.php
index 84e282d..686d362 100644
--- a/src/Console/Command/WinlibsCommand.php
+++ b/src/Console/Command/WinlibsCommand.php
@@ -60,7 +60,7 @@ public function handle(): int
}
}
- (new Helpers)->rmdirr($directoryPath);
+ Helpers::rmdirr($directoryPath);
unlink($directoryPath . '.lock');
}
diff --git a/src/Helpers/Helpers.php b/src/Helpers/Helpers.php
index 670570b..0e07a42 100644
--- a/src/Helpers/Helpers.php
+++ b/src/Helpers/Helpers.php
@@ -5,7 +5,7 @@
class Helpers
{
- public function rmdirr($node): bool
+ public static function rmdirr($node): bool
{
if (!file_exists($node)) {
return false;
@@ -18,7 +18,7 @@ public function rmdirr($node): bool
if ($leaf == '.' || $leaf == '..') {
continue;
}
- $this->rmdirr($node . DIRECTORY_SEPARATOR . $leaf);
+ self::rmdirr($node . DIRECTORY_SEPARATOR . $leaf);
}
$dir->close();
return rmdir($node);
diff --git a/tests/Actions/GetArtifactsTest.php b/tests/Actions/GetArtifactsTest.php
index bdc8a90..92c1f46 100644
--- a/tests/Actions/GetArtifactsTest.php
+++ b/tests/Actions/GetArtifactsTest.php
@@ -26,7 +26,7 @@ public function handle($workflow_run_id, $token): void
$workflowRunDirectory = getenv('BUILDS_DIRECTORY') . "/winlibs/" . $workflow_run_id;
if (is_dir($workflowRunDirectory)) {
- (new Helpers)->rmdirr($workflowRunDirectory);
+ Helpers::rmdirr($workflowRunDirectory);
}
mkdir($workflowRunDirectory, 0755, true);
foreach ($data['artifacts'] as $artifact) {
@@ -59,7 +59,7 @@ public function tearDown(): void
{
$workflowRunDirectory = getenv('BUILDS_DIRECTORY') . "/winlibs/123456";
if (is_dir($workflowRunDirectory)) {
- (new Helpers)->rmdirr($workflowRunDirectory);
+ Helpers::rmdirr($workflowRunDirectory);
}
}
}
diff --git a/tests/Actions/GetListingTest.php b/tests/Actions/GetListingTest.php
index 01c83fa..29ed332 100644
--- a/tests/Actions/GetListingTest.php
+++ b/tests/Actions/GetListingTest.php
@@ -25,7 +25,7 @@ protected function setUp(): void
protected function tearDown(): void
{
- (new Helpers())->rmdirr($this->tempDir);
+ Helpers::rmdirr($this->tempDir);
}
public static function bytes2StringProvider(): array
diff --git a/tests/Actions/UpdateReleasesJsonTest.php b/tests/Actions/UpdateReleasesJsonTest.php
index 12093c6..89b3a3b 100644
--- a/tests/Actions/UpdateReleasesJsonTest.php
+++ b/tests/Actions/UpdateReleasesJsonTest.php
@@ -27,7 +27,7 @@ protected function setUp(): void
protected function tearDown(): void
{
- (new Helpers())->rmdirr($this->tempDir);
+ Helpers::rmdirr($this->tempDir);
}
/**
diff --git a/tests/Console/Command/PeclCommandTest.php b/tests/Console/Command/PeclCommandTest.php
index 9ac7013..005203f 100644
--- a/tests/Console/Command/PeclCommandTest.php
+++ b/tests/Console/Command/PeclCommandTest.php
@@ -35,8 +35,8 @@ protected function tearDown(): void
{
parent::tearDown();
- (new Helpers)->rmdirr($this->baseDirectory);
- (new Helpers)->rmdirr($this->buildsDirectory);
+ Helpers::rmdirr($this->baseDirectory);
+ Helpers::rmdirr($this->buildsDirectory);
}
public function testPeclAddSuccessfullyExtractsZip(): void
@@ -64,7 +64,7 @@ public function testPeclAddFailsWithoutBaseDirectory(): void
$this->assertEquals('Base directory is required', $output);
$this->assertEquals(1, $result);
- (new Helpers)->rmdirr($this->buildsDirectory . '/pecl');
+ Helpers::rmdirr($this->buildsDirectory . '/pecl');
$command->setOption('base-directory', $this->baseDirectory);
$command->setOption('builds-directory', $this->buildsDirectory);
$result = $command->handle();
diff --git a/tests/Console/Command/PhpCommandTest.php b/tests/Console/Command/PhpCommandTest.php
index a3d22ed..ac090a0 100644
--- a/tests/Console/Command/PhpCommandTest.php
+++ b/tests/Console/Command/PhpCommandTest.php
@@ -33,8 +33,8 @@ protected function tearDown(): void
{
parent::tearDown();
// Clean up directories
- (new Helpers)->rmdirr($this->baseDirectory);
- (new Helpers)->rmdirr($this->buildsDirectory);
+ Helpers::rmdirr($this->baseDirectory);
+ Helpers::rmdirr($this->buildsDirectory);
}
public static function buildsProvider(): array
diff --git a/tests/Console/Command/SeriesDeleteCommandTest.php b/tests/Console/Command/SeriesDeleteCommandTest.php
index b3dbd2b..6968528 100644
--- a/tests/Console/Command/SeriesDeleteCommandTest.php
+++ b/tests/Console/Command/SeriesDeleteCommandTest.php
@@ -25,8 +25,8 @@ protected function setUp(): void
protected function tearDown(): void
{
- (new Helpers)->rmdirr($this->baseDirectory);
- (new Helpers)->rmdirr($this->buildsDirectory);
+ Helpers::rmdirr($this->baseDirectory);
+ Helpers::rmdirr($this->buildsDirectory);
parent::tearDown();
}
diff --git a/tests/Console/Command/SeriesInitCommandTest.php b/tests/Console/Command/SeriesInitCommandTest.php
index 24b7d59..106bb21 100644
--- a/tests/Console/Command/SeriesInitCommandTest.php
+++ b/tests/Console/Command/SeriesInitCommandTest.php
@@ -25,8 +25,8 @@ protected function setUp(): void
protected function tearDown(): void
{
- (new Helpers)->rmdirr($this->baseDirectory);
- (new Helpers)->rmdirr($this->buildsDirectory);
+ Helpers::rmdirr($this->baseDirectory);
+ Helpers::rmdirr($this->buildsDirectory);
parent::tearDown();
}
diff --git a/tests/Console/Command/SeriesStabilityCommandTest.php b/tests/Console/Command/SeriesStabilityCommandTest.php
index 0203f29..ccbc3f3 100644
--- a/tests/Console/Command/SeriesStabilityCommandTest.php
+++ b/tests/Console/Command/SeriesStabilityCommandTest.php
@@ -25,8 +25,8 @@ protected function setUp(): void
protected function tearDown(): void
{
- (new Helpers)->rmdirr($this->baseDirectory);
- (new Helpers)->rmdirr($this->buildsDirectory);
+ Helpers::rmdirr($this->baseDirectory);
+ Helpers::rmdirr($this->buildsDirectory);
parent::tearDown();
}
diff --git a/tests/Console/Command/SeriesUpdateCommandTest.php b/tests/Console/Command/SeriesUpdateCommandTest.php
index 011126f..2d1a677 100644
--- a/tests/Console/Command/SeriesUpdateCommandTest.php
+++ b/tests/Console/Command/SeriesUpdateCommandTest.php
@@ -24,8 +24,8 @@ protected function setUp(): void
protected function tearDown(): void
{
- (new Helpers)->rmdirr($this->baseDirectory);
- (new Helpers)->rmdirr($this->buildsDirectory);
+ Helpers::rmdirr($this->baseDirectory);
+ Helpers::rmdirr($this->buildsDirectory);
parent::tearDown();
}
diff --git a/tests/Console/Command/WinlibsCommandTest.php b/tests/Console/Command/WinlibsCommandTest.php
index b531b22..4629c15 100644
--- a/tests/Console/Command/WinlibsCommandTest.php
+++ b/tests/Console/Command/WinlibsCommandTest.php
@@ -30,8 +30,8 @@ protected function setUp(): void
protected function tearDown(): void
{
parent::tearDown();
- (new Helpers)->rmdirr($this->baseDirectory);
- (new Helpers)->rmdirr($this->buildsDirectory);
+ Helpers::rmdirr($this->baseDirectory);
+ Helpers::rmdirr($this->buildsDirectory);
}
#[DataProvider('versionProvider')]
diff --git a/tests/Helpers/HelpersTest.php b/tests/Helpers/HelpersTest.php
index 24ef410..4fc9fb9 100644
--- a/tests/Helpers/HelpersTest.php
+++ b/tests/Helpers/HelpersTest.php
@@ -21,15 +21,13 @@ protected function tearDown(): void
parent::tearDown();
// Ensure all files and directories are cleaned up after each test
if (file_exists($this->testDir)) {
- $helper = new Helpers();
- $helper->rmdirr($this->testDir);
+ Helpers::rmdirr($this->testDir);
}
}
public function testRemoveNonExistentDirectory(): void
{
- $helper = new Helpers();
- $this->assertFalse($helper->rmdirr($this->testDir . '/nonexistent'));
+ $this->assertFalse(Helpers::rmdirr($this->testDir . '/nonexistent'));
}
public function testRemoveDirectoryWithFiles(): void
@@ -37,8 +35,7 @@ public function testRemoveDirectoryWithFiles(): void
mkdir($this->testDir, 0777, true);
file_put_contents($this->testDir . '/file.txt', 'Hello World');
- $helper = new Helpers();
- $result = $helper->rmdirr($this->testDir);
+ $result = Helpers::rmdirr($this->testDir);
$this->assertTrue($result);
$this->assertDirectoryDoesNotExist($this->testDir);
}
@@ -48,8 +45,7 @@ public function testRemoveDirectoryWithNestedDirectories(): void
mkdir($this->testDir . '/nested', 0777, true);
file_put_contents($this->testDir . '/nested/file.txt', 'Hello World');
- $helper = new Helpers();
- $result = $helper->rmdirr($this->testDir);
+ $result = Helpers::rmdirr($this->testDir);
$this->assertTrue($result);
$this->assertDirectoryDoesNotExist($this->testDir);
}
diff --git a/tests/Http/Controllers/DeletePendingJobControllerTest.php b/tests/Http/Controllers/DeletePendingJobControllerTest.php
index c8694a3..79bf0d5 100644
--- a/tests/Http/Controllers/DeletePendingJobControllerTest.php
+++ b/tests/Http/Controllers/DeletePendingJobControllerTest.php
@@ -21,7 +21,7 @@ protected function setUp(): void
protected function tearDown(): void
{
- (new Helpers())->rmdirr($this->tempDir);
+ Helpers::rmdirr($this->tempDir);
parent::tearDown();
}
diff --git a/tests/Http/Controllers/SeriesUpdateControllerTest.php b/tests/Http/Controllers/SeriesUpdateControllerTest.php
index ff252b7..72ae176 100644
--- a/tests/Http/Controllers/SeriesUpdateControllerTest.php
+++ b/tests/Http/Controllers/SeriesUpdateControllerTest.php
@@ -25,7 +25,7 @@ protected function setUp(): void
protected function tearDown(): void
{
putenv($this->originalBuildsDirectory === null ? 'BUILDS_DIRECTORY' : 'BUILDS_DIRECTORY=' . $this->originalBuildsDirectory);
- (new Helpers)->rmdirr($this->buildsDirectory);
+ Helpers::rmdirr($this->buildsDirectory);
parent::tearDown();
}