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 — master ( c45f40...f7d778 )
by Freek
01:36
created

Varnish::generateBanCommand()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 9
nc 2
nop 1
dl 0
loc 16
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Spatie\Varnish;
4
5
use Symfony\Component\Process\Exception\ProcessFailedException;
6
use Symfony\Component\Process\Process;
7
8
class Varnish
9
{
10
    /**
11
     * @param string|array $host
12
     *
13
     * @return \Symfony\Component\Process\Process
14
     */
15
    public function flush($host = null)
16
    {
17
        $host = $this->getHosts($host);
18
19
        $command = $this->generateBanCommand($host);
20
21
        return $this->executeCommand($command);
22
    }
23
24
    /**
25
     * @param array|string $host
26
     *
27
     * @return array
28
     */
29
    protected function getHosts($host = null): array
30
    {
31
        $host = $host ?? config('laravel-varnish.host');
32
33
        if (! is_array($host)) {
34
            $host = [$host];
35
        }
36
37
        return $host;
38
    }
39
40
    public function generateBanCommand(array $hosts): string
41
    {
42
        if (! is_array($hosts)) {
43
            $hosts = [$hosts];
44
        }
45
46
        $hostsRegex = collect($hosts)
47
            ->map(function (string $host) {
48
                return "(^{$host}$)";
49
            })
50
            ->implode('|');
51
52
        $config = config('laravel-varnish');
53
54
        return "sudo varnishadm -S {$config['secret']} -T 127.0.0.1:{$config['administrative_port']} 'ban req.http.host ~ {$hostsRegex}'";
55
    }
56
57
    protected function executeCommand(string $command): Process
58
    {
59
        $process = new Process($command);
60
61
        $process->run();
62
63
        if (! $process->isSuccessful()) {
64
            throw new ProcessFailedException($process);
65
        }
66
67
        return $process;
68
    }
69
}
70