Failed Conditions
Push — master ( ac05b5...2858d3 )
by Keoghan
02:49
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
     * @return void
12
     */
13
    public function trustCA($pem)
14
    {
15
        $this->consoleWriter->info('Auto Trust CA Certificate, needs sudo privilege. Please provide your sudo password.');
16
17
        $command = "sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain {$pem}";
18
19
        if($this->isTesting()) {
20
            $this->consoleWriter->info("Did not trust CA during testing.");
21
            return;
22
        }
23
24
        $this->cli->passthru($command);
25
    }
26
27
    /**
28
     * Trust the given certificate file in the Mac Keychain.
29
     *
30
     * @param  string  $crt
31
     * @return void
32
     */
33
    public function trustCertificate($crt)
34
    {
35
        $this->consoleWriter->info('Auto Trust Certificate, needs sudo privilege. Please provide your sudo password.');
36
37
        $command = "sudo security add-trusted-cert -d -r trustAsRoot -k /Library/Keychains/System.keychain {$crt}";
38
39
        if($this->isTesting()) {
40
            $this->consoleWriter->info("Did not trust Certificate during testing.");
41
            return;
42
        }
43
44
        $this->cli->passthru($command);
45
    }
46
47
    /**
48
     * Return the User's home directory path
49
     *
50
     * @return string
51
     */
52 1
    public function getUserHomePath()
53
    {
54 1
        return $this->serverBag->get('HOME');
55
    }
56
57
    /**
58
     * Flush the host system DNS cache
59
     *
60
     * @return void
61
     */
62 1
    public function flushDns()
63
    {
64 1
        $this->consoleWriter->info('Flushing DNS. Requires sudo permissions.');
65 1
        $this->cli->passthru('sudo killall -HUP mDNSResponder');
66 1
    }
67
}
68