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.
Passed
Push — develop ( 58991a...ed3764 )
by Baptiste
04:02
created

ComposerUpdate   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
eloc 31
dl 0
loc 52
ccs 29
cts 29
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
B __invoke() 0 43 6
A __construct() 0 3 1
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 12
    public function __construct(Processes $processes)
27
    {
28 12
        $this->processes = $processes;
29 12
    }
30
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
            });
75 4
    }
76
}
77