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.

Profiler::start()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 24
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 15
CRAP Score 4

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 14
c 1
b 0
f 1
dl 0
loc 24
ccs 15
cts 15
cp 1
rs 9.7998
cc 4
nc 4
nop 2
crap 4
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 20
    public function __construct(Filesystem $filesystem, Processes $processes)
34
    {
35 20
        $this->filesystem = $filesystem;
36 20
        $this->processes = $processes;
37 20
        $this->dotenv = new Dotenv;
38 20
    }
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())
0 ignored issues
show
Deprecated Code introduced by
The function Innmind\Url\Url::fromString() has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

87
                ->withArgument((string) /** @scrutinizer ignore-deprecated */ Url::fromString($env['PROFILER'])->authority())
Loading history...
88 2
                ->withWorkingDirectory($workingDirectory)
89
        );
90 2
    }
91
}
92