| Conditions | 6 |
| Paths | 3 |
| Total Lines | 43 |
| Code Lines | 28 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 26 |
| CRAP Score | 6 |
| Changes | 0 | ||
| 1 | <?php |
||
| 31 | 8 | public function __invoke(Activity $activity, Environment $env): void |
|
| 32 | { |
||
| 33 | 8 | if (!$activity->is(Type::start())) { |
|
| 34 | 2 | return; |
|
| 35 | } |
||
| 36 | |||
| 37 | 6 | $output = $env->output(); |
|
| 38 | 6 | $error = $env->error(); |
|
| 39 | |||
| 40 | 6 | $ask = new Question('Update dependencies? [Y/n]'); |
|
| 41 | 6 | $response = (string) $ask($env->input(), $output); |
|
| 42 | |||
| 43 | 6 | if (($response ?: 'y') === 'n') { |
|
| 44 | 2 | return; |
|
| 45 | } |
||
| 46 | |||
| 47 | $this |
||
| 48 | 4 | ->processes |
|
| 49 | 4 | ->execute( |
|
| 50 | 4 | Command::foreground('composer') |
|
| 51 | 4 | ->withOption('ansi') |
|
| 52 | 4 | ->withArgument('update') |
|
| 53 | 4 | ->withWorkingDirectory((string) $env->workingDirectory()) |
|
| 54 | ) |
||
| 55 | 4 | ->output() |
|
| 56 | ->foreach(static function(Str $line, Output\Type $type) use ($output, $error): void { |
||
| 57 | 4 | if ($type === Output\Type::output()) { |
|
| 58 | 4 | $stream = $output; |
|
| 59 | } else { |
||
| 60 | 2 | $stream = $error; |
|
| 61 | } |
||
| 62 | |||
| 63 | 4 | if (!$line->contains("\n")) { |
|
| 64 | 2 | $stream->write($line); |
|
| 65 | |||
| 66 | 2 | return; |
|
| 67 | } |
||
| 68 | |||
| 69 | 2 | $lines = $line->split("\n"); |
|
| 70 | $lines->dropEnd(1)->foreach(static function($line) use ($stream): void { |
||
| 71 | 2 | $stream->write($line->append("\n")); |
|
| 72 | 2 | }); |
|
| 73 | 2 | $stream->write($lines->last()); |
|
| 74 | 4 | }); |
|
| 77 |