Task   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 50
rs 10
c 0
b 0
f 0
wmc 9

6 Methods

Rating   Name   Duplication   Size   Complexity  
A isRemote() 0 3 1
A getEnvVars() 0 3 1
A isLocal() 0 9 3
A getServers() 0 3 1
A __construct() 0 9 2
A getShellCommand() 0 3 1
1
<?php
2
3
4
namespace Bencagri\Artisan\Deployer\Task;
5
6
use Bencagri\Artisan\Deployer\Server\Server;
7
8
class Task
9
{
10
    /** @var Server[] $servers */
11
    private $servers;
12
    private $shellCommand;
13
    private $envVars;
14
15
    public function __construct(array $servers, string $shellCommand, array $envVars = [])
16
    {
17
        if (empty($servers)) {
18
            throw new \InvalidArgumentException('The "servers" argument of a Task cannot be an empty array. Add at least one server.');
19
        }
20
21
        $this->servers = $servers;
22
        $this->shellCommand = $shellCommand;
23
        $this->envVars = $envVars;
24
    }
25
26
    /**
27
     * @return Server[]
28
     */
29
    public function getServers() : array
30
    {
31
        return $this->servers;
32
    }
33
34
    public function isLocal() : bool
35
    {
36
        foreach ($this->servers as $server) {
37
            if (!$server->isLocalHost()) {
38
                return false;
39
            }
40
        }
41
42
        return true;
43
    }
44
45
    public function isRemote() : bool
46
    {
47
        return !$this->isLocal();
48
    }
49
50
    public function getShellCommand() : string
51
    {
52
        return $this->shellCommand;
53
    }
54
55
    public function getEnvVars() : array
56
    {
57
        return $this->envVars;
58
    }
59
}
60