MachineState   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 14
dl 0
loc 34
rs 10
c 0
b 0
f 0
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A isRunning() 0 11 2
A exists() 0 9 2
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