GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

ComposerUpdate::__invoke()   A
last analyzed

Complexity

Conditions 5
Paths 3

Size

Total Lines 33
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 21
CRAP Score 5

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 22
c 2
b 0
f 0
dl 0
loc 33
ccs 21
cts 21
cp 1
rs 9.2568
cc 5
nc 3
nop 2
crap 5
1
<?php
2
declare(strict_types = 1);
3
4
namespace Innmind\LabStation\Trigger;
5
6
use Innmind\LabStation\{
7
    Trigger,
8
    Activity,
9
    Activity\Type,
10
};
11
use Innmind\CLI\{
12
    Environment,
13
    Question\Question,
14
};
15
use Innmind\Server\Control\Server\{
16
    Processes,
17
    Command,
18
    Process\Output,
19
};
20
use Innmind\Immutable\Str;
21
22
final class ComposerUpdate implements Trigger
23
{
24
    private $processes;
25
26 10
    public function __construct(Processes $processes)
27
    {
28 10
        $this->processes = $processes;
29 10
    }
30
31 6
    public function __invoke(Activity $activity, Environment $env): void
32
    {
33 6
        if (!$activity->is(Type::start())) {
34 2
            return;
35
        }
36
37 4
        $output = $env->output();
38 4
        $error = $env->error();
39
40 4
        $ask = new Question('Update dependencies? [Y/n]');
41 4
        $response = (string) $ask($env->input(), $output);
42
43 4
        if (($response ?: 'y') === 'n') {
44 2
            return;
45
        }
46
47
        $this
48 2
            ->processes
49 2
            ->execute(
50 2
                Command::foreground('composer')
51 2
                    ->withOption('ansi')
52 2
                    ->withArgument('update')
53 2
                    ->withWorkingDirectory((string) $env->workingDirectory())
54
            )
55 2
            ->output()
56
            ->foreach(static function(Str $line, Output\Type $type) use ($output, $error): void {
57 2
                if ($type === Output\Type::output()) {
58 2
                    $output->write($line);
59
                } else {
60 2
                    $error->write($line);
61
                }
62 2
            });
63 2
        $output->write(Str::of("Dependencies updated!\n"));
64 2
    }
65
}
66