Failed Conditions
Push — master ( ac05b5...2858d3 )
by Keoghan
02:49
created

MacOs   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Test Coverage

Coverage 23.81%

Importance

Changes 0
Metric Value
wmc 6
eloc 16
dl 0
loc 61
ccs 5
cts 21
cp 0.2381
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A trustCA() 0 12 2
A trustCertificate() 0 12 2
A getUserHomePath() 0 3 1
A flushDns() 0 4 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