Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
10 / 10 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| ComposerSelfUpdateRunner | |
100.00% |
10 / 10 |
|
100.00% |
2 / 2 |
4 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| update | |
100.00% |
9 / 9 |
|
100.00% |
1 / 1 |
3 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | /** |
| 6 | * Fast Forward Development Tools for PHP projects. |
| 7 | * |
| 8 | * This file is part of fast-forward/dev-tools project. |
| 9 | * |
| 10 | * @author Felipe Sayão Lobato Abreu <github@mentordosnerds.com> |
| 11 | * @license https://opensource.org/licenses/MIT MIT License |
| 12 | * |
| 13 | * @see https://github.com/php-fast-forward/ |
| 14 | * @see https://github.com/php-fast-forward/dev-tools |
| 15 | * @see https://github.com/php-fast-forward/dev-tools/issues |
| 16 | * @see https://php-fast-forward.github.io/dev-tools/ |
| 17 | * @see https://datatracker.ietf.org/doc/html/rfc2119 |
| 18 | */ |
| 19 | |
| 20 | namespace FastForward\DevTools\SelfUpdate; |
| 21 | |
| 22 | use FastForward\DevTools\Process\ProcessBuilderInterface; |
| 23 | use FastForward\DevTools\Process\ProcessQueueInterface; |
| 24 | use Symfony\Component\Console\Output\OutputInterface; |
| 25 | |
| 26 | /** |
| 27 | * Updates DevTools through the active Composer executable. |
| 28 | */ |
| 29 | class ComposerSelfUpdateRunner implements SelfUpdateRunnerInterface |
| 30 | { |
| 31 | private const string PACKAGE = 'fast-forward/dev-tools'; |
| 32 | |
| 33 | /** |
| 34 | * @param ProcessBuilderInterface $processBuilder the process builder used to assemble Composer update commands |
| 35 | * @param ProcessQueueInterface $processQueue the queue used to execute the update process |
| 36 | */ |
| 37 | public function __construct( |
| 38 | private ProcessBuilderInterface $processBuilder, |
| 39 | private ProcessQueueInterface $processQueue, |
| 40 | ) {} |
| 41 | |
| 42 | /** |
| 43 | * Updates the installed DevTools package. |
| 44 | * |
| 45 | * @param bool $global whether the update should target Composer's global project |
| 46 | * @param OutputInterface $output the command output used by the update process |
| 47 | * |
| 48 | * @return int the Composer process status code |
| 49 | */ |
| 50 | public function update(bool $global, OutputInterface $output): int |
| 51 | { |
| 52 | $command = $global ? 'composer global update' : 'composer update'; |
| 53 | $label = $global ? 'Updating global DevTools installation' : 'Updating project DevTools installation'; |
| 54 | |
| 55 | $this->processQueue->add( |
| 56 | process: $this->processBuilder |
| 57 | ->withArgument(self::PACKAGE) |
| 58 | ->build($command), |
| 59 | label: $label, |
| 60 | ); |
| 61 | |
| 62 | return $this->processQueue->run($output); |
| 63 | } |
| 64 | } |