Passed
Push — master ( 956163...dedbc7 )
by Christian
03:02
created

CertificateChecker::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace Cocotte\Acme;
4
5
use Cocotte\Console\Style;
6
use Cocotte\Shell\ProcessRunner;
7
use Symfony\Component\Process\Process;
8
9
final class CertificateChecker
10
{
11
    /**
12
     * @var ProcessRunner
13
     */
14
    private $processRunner;
15
    /**
16
     * @var Style
17
     */
18
    private $style;
19
20
    public function __construct(ProcessRunner $processRunner, Style $style)
21
    {
22
        $this->processRunner = $processRunner;
23
        $this->style = $style;
24
    }
25
26
    public function check(string $hostname, string $expectedIp)
27
    {
28
        $ip = gethostbyname($hostname);
29
        if ($ip === $expectedIp) {
30
            $this->processRunner->mustRun(Process::fromShellCommandline(
31
                'if [ "${ACME_ENABLED:-true}" = true ]; then '.
32
                "check-certificate $hostname 6; ".
33
                'else echo "Skipping SSL verification"; fi'
34
            ));
35
        } else {
36
            $this->style->note("Skipping SSL verification because $hostname resolves to {$ip} ".
37
                "instead of machine ip which is $expectedIp\n".
38
                "You should wait for DNS to update or force $hostname to $expectedIp ".
39
                "in your /etc/hosts file.");
40
        }
41
    }
42
}
43