Passed
Push — master ( ce2df3...cb14e2 )
by Robin
05:44 queued 02:43
created

MacOs::flushDns()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
namespace App\Support\Mechanics;
4
5
class MacOs extends Untrained
6
{
7
    /**
8
     * Trust the given root certificate file in the Keychain.
9
     *
10
     * @param string $pem
11
     *
12
     * @return void
13
     */
14
    public function trustCA($pem)
15
    {
16
        $this->consoleWriter->info('Auto Trust CA Certificate, needs sudo privilege. Please provide your sudo password.');
17
18
        $command = "sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain {$pem}";
19
20
        $this->cli->passthru($command);
21
    }
22
23
    /**
24
     * Trust the given certificate file in the Mac Keychain.
25
     *
26
     * @param string $crt
27
     *
28
     * @return void
29
     */
30
    public function trustCertificate($crt)
31
    {
32
        $this->consoleWriter->info('Auto Trust Certificate, needs sudo privilege. Please provide your sudo password.');
33
34
        $command = "sudo security add-trusted-cert -d -r trustAsRoot -k /Library/Keychains/System.keychain {$crt}";
35
36
        $this->cli->passthru($command);
37
    }
38
39
    /**
40
     * Return the User's home directory path.
41
     *
42
     * @return string
43
     */
44 1
    public function getUserHomePath()
45
    {
46 1
        return $this->serverBag->get('HOME');
47
    }
48
49
    /**
50
     * Flush the host system DNS cache.
51
     *
52
     * @return void
53
     */
54 1
    public function flushDns()
55
    {
56 1
        $this->consoleWriter->info('Flushing DNS. Requires sudo permissions.');
57 1
        $this->cli->passthru('sudo killall -HUP mDNSResponder');
58 1
    }
59
}
60