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

WatchCurrentGitBranch::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 12
ccs 6
cts 6
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 5
crap 1
1
<?php
2
declare(strict_types = 1);
3
4
namespace Innmind\LabStation\Agent;
5
6
use Innmind\LabStation\{
7
    Agent,
8
    Protocol,
9
    Activity,
10
    Activity\Type,
11
};
12
use Innmind\FileWatch\Watch;
13
use Innmind\IPC\{
14
    IPC,
15
    Process\Name,
16
};
17
use Innmind\Url\{
18
    PathInterface,
19
    Path,
20
};
21
use Innmind\Git\Git;
22
23
final class WatchCurrentGitBranch implements Agent
24
{
25
    private $git;
26
    private $protocol;
27
    private $watch;
28
    private $ipc;
29
    private $monitor;
30
31 8
    public function __construct(
32
        Git $git,
33
        Protocol $protocol,
34
        Watch $watch,
35
        IPC $ipc,
36
        Name $monitor
37
    ) {
38 8
        $this->git = $git;
39 8
        $this->protocol = $protocol;
40 8
        $this->watch = $watch;
41 8
        $this->ipc = $ipc;
42 8
        $this->monitor = $monitor;
43 8
    }
44
45 4
    public function __invoke(PathInterface $project): void
46
    {
47 4
        $git = new Path($project.'/.git');
48 4
        $repository = $this->git->repository($project);
49 4
        $previousBranch = $repository->head();
50
51
        ($this->watch)($git)(function() use (&$previousBranch, $repository) {
52 4
            $currentBranch = $repository->head();
53
54 4
            if ((string) $currentBranch === (string) $previousBranch) {
55 2
                return;
56
            }
57
58 4
            $previousBranch = $currentBranch;
59 4
            $monitor = $this->ipc->get($this->monitor);
60 4
            $monitor->send(
61 4
                $this->protocol->encode(
62 4
                    new Activity(
63 4
                        Type::gitBranchChanged(),
64 4
                        ['branch' => (string) $currentBranch]
65
                    )
66
                )
67
            );
68 4
            $monitor->close();
69 4
        });
70 4
    }
71
}
72