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 UpdateComposerDevPackageVersion.php
Signed-off-by: Nathanael Esayeas <nathanael.esayeas@protonmail.com>
- Loading branch information
1 parent
e74173a
commit e2d182d
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\ComposerDevPackageTaskInterface; | ||
use Override; | ||
|
||
use function sprintf; | ||
|
||
final readonly class UpdateComposerDevPackageVersion implements ComposerDevPackageTaskInterface | ||
{ | ||
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($path, $package, $version); | ||
} | ||
} | ||
|
||
#[Override] | ||
public function packages(): array | ||
{ | ||
return $this->packages; | ||
} | ||
|
||
private function update(string $path, string $package, string $version): void | ||
{ | ||
(new Process(['composer', 'require', '--dev', sprintf('%s:%s', $package, $version)], $path))->mustRun(); | ||
} | ||
} |