Passed
Push — master ( 3ee5ba...23bbf0 )
by Keoghan
04:26
created

Untrained::isUsingStandardLoopback()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
ccs 0
cts 2
cp 0
rs 10
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
namespace App\Support\Mechanics;
4
5
use App\Support\Console\ConsoleWriter;
6
use App\Support\Console\ServerBag;
7
use App\Support\Contracts\Cli;
8
9
class Untrained implements Mechanic
10
{
11
    /** @var Cli */
12
    protected $cli;
13
14
    /** @var ConsoleWriter */
15
    protected $consoleWriter;
16
17
    /** @var ServerBag */
18
    protected $serverBag;
19
20
    /** @var string Standard Loopback Address */
21
    protected $standardLoopback = '127.0.0.1';
22
23
    /** @var string Alternative Loopback Address */
24
    protected $alternativeLoopback = '127.0.0.1';
25
26
    /**
27
     * Untrained constructor.
28
     *
29
     * @param Cli           $cli
30
     * @param ConsoleWriter $consoleWriter
31
     * @param ServerBag     $serverBag
32
     */
33 134
    public function __construct(Cli $cli, ConsoleWriter $consoleWriter, ServerBag $serverBag)
34
    {
35 134
        $this->cli = $cli;
36 134
        $this->consoleWriter = $consoleWriter;
37 134
        $this->serverBag = $serverBag;
38 134
    }
39
40
    /**
41
     * Trust the given root certificate file in the Keychain.
42
     *
43
     * @param string $pem
44
     *
45
     * @return void
46
     */
47 1
    public function trustCA($pem)
48
    {
49 1
        $this->iAmNotTrainedTo('trust a CA certificate');
50 1
    }
51
52
    /**
53
     * Trust the given certificate file in the Mac Keychain.
54
     *
55
     * @param string $crt
56
     *
57
     * @return void
58
     */
59 1
    public function trustCertificate($crt)
60
    {
61 1
        $this->iAmNotTrainedTo('trust a certificate');
62 1
    }
63
64
    /**
65
     * Return the User's home directory path.
66
     *
67
     * @return string
68
     */
69 1
    public function getUserHomePath()
70
    {
71 1
        $this->iAmNotTrainedTo('get the users home path');
72 1
    }
73
74
    /**
75
     * Flush the host system DNS cache.
76
     *
77
     * @return void
78
     */
79 1
    public function flushDns()
80
    {
81 1
        $this->iAmNotTrainedTo('flush the DNS');
82 1
    }
83
84
    /**
85
     * Give a nice message about not being trained.
86
     *
87
     * @param $activity
88
     */
89 6
    protected function iAmNotTrainedTo($activity)
90
    {
91 6
        $this->consoleWriter->info("I haven't been trained to {$activity} on this system.");
92 6
        $this->consoleWriter->info('You are welcome to train me and submit a PR.');
93 6
    }
94
95
    /**
96
     * Setup networking for Porter.
97
     *
98
     * @return void
99
     */
100 1
    public function addAlternativeLoopbackAddress()
101
    {
102 1
        $this->iAmNotTrainedTo('set up special networking for Porter');
103 1
    }
104
105
    /**
106
     * Restore networking for Porter.
107
     *
108
     * @return void
109
     */
110 1
    public function removeAlternativeLoopbackAddress()
111
    {
112 1
        $this->iAmNotTrainedTo('restore special networking for Porter');
113 1
    }
114
115
    /**
116
     * Get standard loopback address.
117
     *
118
     * @return string
119
     */
120 2
    public function getStandardLoopback()
121
    {
122 2
        return $this->standardLoopback;
123
    }
124
125
    /**
126
     * Get alternative loopback address.
127
     *
128
     * @return string
129
     */
130 1
    public function getAlternativeLoopback()
131
    {
132 1
        return $this->alternativeLoopback;
133
    }
134
135
    /**
136
     * Does a Porter domain resolve to the standard loopback address.
137
     *
138
     * @return bool
139
     */
140
    public function isUsingAlternativeLoopback()
141
    {
142
        return $this->getPorterDomainIp() === $this->getAlternativeLoopback();
143
    }
144
145
    /**
146
     * Does a Porter domain resolve to the standard loopback address?
147
     *
148
     * @return bool
149
     */
150
    public function isUsingStandardLoopback()
151
    {
152
        return $this->getPorterDomainIp() === $this->getStandardLoopback();
153
    }
154
155
    /**
156
     * Determine the working IP for Porter.
157
     *
158
     * @return string
159
     */
160
    public function getPorterDomainIp()
161
    {
162
        $this->iAmNotTrainedTo('obtain the current IP address for Porter');
163
    }
164
}
165