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

MacOs   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Test Coverage

Coverage 33.33%

Importance

Changes 0
Metric Value
wmc 4
eloc 10
dl 0
loc 53
ccs 5
cts 15
cp 0.3333
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A trustCA() 0 7 1
A trustCertificate() 0 7 1
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
     *
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