Skip to content

Commit

Permalink
Add UpdateComposerPackageVersion.php
Browse files Browse the repository at this point in the history
Signed-off-by: Nathanael Esayeas <nathanael.esayeas@protonmail.com>
  • Loading branch information
ghostwriter committed Jul 17, 2024
1 parent 71426a1 commit e74173a
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/Task/UpdateComposerPackageVersion.php
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();
}
}

0 comments on commit e74173a

Please sign in to comment.