Issues (2128)

plugin/bbb/lib/VM.php (1 issue)

Severity
1
<?php
2
/* For licensing terms, see /license.txt */
3
4
/**
5
 * Class VM
6
 */
7
class VM
8
{
9
    protected $config;
10
    public $virtualMachine;
11
12
    /**
13
     * VM constructor.
14
     * @param $config
15
     */
16
    public function __construct($config)
17
    {
18
        $this->config = $config;
19
    }
20
21
    /**
22
     * @return array
23
     */
24
    public function getConfig()
25
    {
26
        return $this->config;
27
    }
28
29
    /**
30
     * @param   bool    $checkEnabled   Check if, additionnally to being installed, the plugin is enabled
31
     * @return bool
32
     */
33
    public function isEnabled(bool $checkEnabled = false): bool
34
    {
35
        $config = $this->getConfig();
36
37
        if (!isset($config)) {
38
39
            return false;
40
        }
41
42
        if (!is_array($config)) {
43
            return false;
44
        }
45
46
        if (isset($config['enabled']) && $config['enabled']) {
47
48
            return true;
49
        }
50
51
        return false;
52
    }
53
54
    /**
55
     * @return VirtualMachineInterface
56
     */
57
    public function getVirtualMachine()
58
    {
59
        return $this->virtualMachine;
60
    }
61
62
    /**
63
     * @param VirtualMachineInterface $virtualMachine
64
     */
65
    public function setVirtualMachine(VirtualMachineInterface $virtualMachine)
66
    {
67
        $this->virtualMachine = $virtualMachine;
68
    }
69
70
    /**
71
     * @return VirtualMachineInterface
72
     */
73
    public function getVirtualMachineFromConfig()
74
    {
75
        $vmList = $this->config['vms'];
76
77
        foreach ($vmList as $vm) {
78
            if (isset($vm['enabled']) && $vm['enabled'] == true) {
79
                $className = $vm['name'].'VM';
80
81
                return new $className($vm);
82
                break;
0 ignored issues
show
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
83
            }
84
        }
85
86
        return false;
87
    }
88
89
    /**
90
     * Resize the VM to the max size
91
     */
92
    public function resizeToMaxLimit()
93
    {
94
        $virtualMachine = $this->getVirtualMachineFromConfig();
95
        $this->setVirtualMachine($virtualMachine);
96
        $virtualMachine->resizeToMaxLimit();
97
    }
98
99
    /**
100
     * Resize the VM to the min size
101
     */
102
    public function resizeToMinLimit()
103
    {
104
        $virtualMachine = $this->getVirtualMachineFromConfig();
105
        $this->setVirtualMachine($virtualMachine);
106
        $virtualMachine->resizeToMinLimit();
107
    }
108
109
    public function runCron()
110
    {
111
        $virtualMachine = $this->getVirtualMachineFromConfig();
112
        $this->setVirtualMachine($virtualMachine);
113
114
        $virtualMachine->runCron();
115
    }
116
}
117