AbstractConfiguration   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 28
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A server() 0 9 2
A __construct() 0 3 1
A useSshAgentForwarding() 0 3 1
1
<?php
2
3
namespace Bencagri\Artisan\Deployer\Configuration;
4
5
use Bencagri\Artisan\Deployer\Exception\InvalidConfigurationException;
6
use Bencagri\Artisan\Deployer\Server\Property;
7
use Bencagri\Artisan\Deployer\Server\Server;
8
use Bencagri\Artisan\Deployer\Server\ServerRepository;
9
10
11
abstract class AbstractConfiguration
12
{
13
    private const RESERVED_SERVER_PROPERTIES = [Property::use_ssh_agent_forwarding];
14
    protected $servers;
15
    protected $useSshAgentForwarding = true;
16
17
    public function __construct()
18
    {
19
        $this->servers = new ServerRepository();
20
    }
21
22
    public function server(string $sshDsn, array $roles = [Server::ROLE_APP], array $properties = [])
23
    {
24
        $reservedProperties = array_merge(self::RESERVED_SERVER_PROPERTIES, $this->getReservedServerProperties());
25
        $reservedPropertiesUsed = array_intersect($reservedProperties, array_keys($properties));
26
        if (!empty($reservedPropertiesUsed)) {
27
            throw new InvalidConfigurationException(sprintf('These properties set for the "%s" server are reserved: %s. Use different property names.', $sshDsn, implode(', ', $reservedPropertiesUsed)));
28
        }
29
30
        $this->servers->add(new Server($sshDsn, $roles, $properties));
31
    }
32
33
    public function useSshAgentForwarding(bool $useIt)
34
    {
35
        $this->useSshAgentForwarding = $useIt;
36
    }
37
38
    abstract protected function getReservedServerProperties() : array;
39
}
40