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.
Completed
Push — develop ( 8a6344...962010 )
by Baptiste
02:40
created

Profiler::__invoke()   A

Complexity

Conditions 5
Paths 5

Size

Total Lines 23
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 5

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 23
ccs 12
cts 12
cp 1
rs 9.6111
c 0
b 0
f 0
cc 5
nc 5
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\Environment;
12
use Innmind\OperatingSystem\Filesystem;
13
use Innmind\Filesystem\{
14
    Directory,
15
    File,
16
};
17
use Innmind\Server\Control\Server\{
18
    Processes,
19
    Command,
20
};
21
use Innmind\Url\{
22
    Url,
23
    PathInterface,
24
};
25
use Symfony\Component\Dotenv\Dotenv;
26
27
final class Profiler implements Trigger
28
{
29
    private $filesystem;
30
    private $processes;
31
    private $dotenv;
32
33 18
    public function __construct(Filesystem $filesystem, Processes $processes)
34
    {
35 18
        $this->filesystem = $filesystem;
36 18
        $this->processes = $processes;
37 18
        $this->dotenv = new Dotenv;
38 18
    }
39
40 16
    public function __invoke(Activity $activity, Environment $env): void
41
    {
42 16
        if (!$activity->is(Type::start())) {
43 2
            return;
44
        }
45
46 14
        $project = $this->filesystem->mount($env->workingDirectory());
47
48 14
        if (!$project->has('config')) {
49 2
            return;
50
        }
51
52 12
        $config = $project->get('config');
53
54 12
        if (!$config instanceof Directory) {
55 2
            return;
56
        }
57
58 10
        if (!$config->has('.env')) {
59 2
            return;
60
        }
61
62 8
        $this->start($config->get('.env'), $env->workingDirectory());
63 8
    }
64
65 8
    private function start(File $file, PathInterface $workingDirectory): void
66
    {
67 8
        $env = $this->dotenv->parse((string) $file->content());
68
69 8
        if (!\array_key_exists('DEBUG', $env)) {
70 2
            return;
71
        }
72
73 6
        if ($env['DEBUG'] != true) {
74 2
            return;
75
        }
76
77 4
        if (!\array_key_exists('PROFILER', $env)) {
78 2
            return;
79
        }
80
81 2
        $workingDirectory = \rtrim((string) $workingDirectory, '/');
82 2
        $workingDirectory .= '/../profiler/public';
83
84 2
        $this->processes->execute(
85 2
            Command::background('php')
86 2
                ->withShortOption('S')
87 2
                ->withArgument((string) Url::fromString($env['PROFILER'])->authority())
88 2
                ->withWorkingDirectory($workingDirectory)
89
        );
90 2
    }
91
}
92