generated from ghostwriter/wip
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add UpdateComposerPackageVersion.php
Signed-off-by: Nathanael Esayeas <nathanael.esayeas@protonmail.com>
- Loading branch information
1 parent
71426a1
commit e74173a
Showing
1 changed file
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Ghostwriter\Arm\Task; | ||
|
||
use Ghostwriter\Arm\Configuration\Process; | ||
use Ghostwriter\Arm\Interface\Task\Composer\ComposerPackageTaskInterface; | ||
use Override; | ||
|
||
use function sprintf; | ||
|
||
final readonly class UpdateComposerPackageVersion implements ComposerPackageTaskInterface | ||
{ | ||
public function __construct( | ||
private array $packages | ||
) { | ||
} | ||
|
||
#[Override] | ||
public function __invoke(string $organization, string $repository): void | ||
{ | ||
$path = sprintf('%s/%s', $organization, $repository); | ||
|
||
foreach ($this->packages as $package => $version) { | ||
$this->update($package, $version, $path); | ||
} | ||
} | ||
|
||
#[Override] | ||
public function packages(): array | ||
{ | ||
return $this->packages; | ||
} | ||
|
||
private function update(string $package, string $path, string $version): void | ||
{ | ||
(new Process(['composer', 'require', sprintf('%s:%s', $package, $version)], $path))->mustRun(); | ||
} | ||
} |