MachineState::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace Cocotte\Machine;
4
5
use Symfony\Component\Process\Process;
6
7
class MachineState
8
{
9
    /**
10
     * @var MachineName
11
     */
12
    private $machineName;
13
14
    public function __construct(MachineName $machineName)
15
    {
16
        $this->machineName = $machineName;
17
    }
18
19
    public function exists(): bool
20
    {
21
        $process = Process::fromShellCommandline('docker-machine ls -q --filter="name=${MACHINE_NAME}"');
22
        $process->run();
23
        if ($process->isSuccessful()) {
24
            return $this->machineName->toString() === trim($process->getOutput());
25
        }
26
27
        return false;
28
    }
29
30
    public function isRunning(): bool
31
    {
32
        $process = Process::fromShellCommandline(
33
            'docker-machine ls -q --filter="state=running" --filter="name=${MACHINE_NAME}"'
34
        );
35
        $process->run();
36
        if ($process->isSuccessful()) {
37
            return $this->machineName->toString() === trim($process->getOutput());
38
        }
39
40
        return false;
41
    }
42
}
43