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 ( 665c4b...facf96 )
by Baptiste
02:22
created

GitRelease   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 9
eloc 43
dl 0
loc 70
ccs 40
cts 40
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
B __invoke() 0 57 8
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
    Question\ChoiceQuestion,
15
};
16
use Innmind\Git\{
17
    Git,
18
    Message,
19
    Exception\DomainException,
20
};
21
use Innmind\GitRelease\{
22
    Release,
23
    LatestVersion,
24
};
25
use Innmind\Immutable\{
26
    Map,
27
    Str,
28
};
29
30
final class GitRelease implements Trigger
31
{
32
    private $git;
33
    private $release;
34
    private $latestVersion;
35
36 20
    public function __construct(Git $git, Release $release, LatestVersion $latestVersion)
37
    {
38 20
        $this->git = $git;
39 20
        $this->release = $release;
40 20
        $this->latestVersion = $latestVersion;
41 20
    }
42
43 16
    public function __invoke(Activity $activity, Environment $env): void
44
    {
45 16
        if (!$activity->is(Type::gitBranchChanged())) {
46 2
            return;
47
        }
48
49 14
        if ($activity->data()['branch'] !== 'master') {
50 2
            return;
51
        }
52
53 12
        $repository = $this->git->repository($env->workingDirectory());
54 12
        $version = ($this->latestVersion)($repository);
55
56 12
        $env->output()->write(Str::of("$version\n"));
57
58 12
        $ask = new ChoiceQuestion(
59 12
            'Kind of release:',
60 12
            Map::of('scalar', 'scalar')
61 12
                (1, 'major')
62 12
                (2, 'minor')
63 12
                (3, 'bugfix')
64 12
                (4, 'none')
65
        );
66 12
        $response = $ask($env->input(), $env->output());
67
68 12
        if ($response->empty()) {
69 2
            return;
70
        }
71
72 10
        switch ($response->current()) {
73 10
            case 'major':
74 4
                $version = $version->increaseMajor();
75 4
                break;
76
77 6
            case 'minor':
78 2
                $version = $version->increaseMinor();
79 2
                break;
80
81 4
            case 'bugfix':
82 2
                $version = $version->increaseBugfix();
83 2
                break;
84
85
            default:
86 2
                return;
87
        }
88
89 8
        $message = (new Question('message:'))($env->input(), $env->output());
90
91
        try {
92 8
            $message = new Message((string) $message);
93 2
        } catch (DomainException $e) {
94 2
            $env->error()->write(Str::of("Invalid message\n"));
95
96 2
            return;
97
        }
98
99 6
        ($this->release)($repository, $version, $message);
100 6
    }
101
}
102