Completed
Push — master ( c5a3b4...fa0d52 )
by Arne
01:49
created

Configuration::setConnectionConfigurations()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 1
1
<?php
2
3
namespace Archivr;
4
5
use Archivr\Exception\Exception;
6
7
class Configuration
8
{
9
    /**
10
     * The local base path of the archive.
11
     *
12
     * @var string
13
     */
14
    protected $localPath;
15
16
    /**
17
     * Set of excluded paths.
18
     *
19
     * @var string[]
20
     */
21
    protected $exclusions = [];
22
23
    /**
24
     * Identity to be visible in synchronization log.
25
     *
26
     * @var string
27
     */
28
    protected $identity;
29
30
    /**
31
     * Map of vault configurations by identifier.
32
     *
33
     * @var VaultConfiguration[]
34
     */
35
    protected $vaultConfigurations = [];
36
37
    /**
38
     * @return string
39
     */
40
    public function getLocalPath(): string
41
    {
42
        return $this->localPath;
43
    }
44
45
    /**
46
     * @param string $localPath
47
     *
48
     * @return Configuration
49
     */
50
    public function setLocalPath(string $localPath): Configuration
51
    {
52
        $this->localPath = $localPath;
53
54
        return $this;
55
    }
56
57
    /**
58
     * @return \string[]
59
     */
60
    public function getExclusions(): array
61
    {
62
        return $this->exclusions;
63
    }
64
65
    /**
66
     * @param \string[] $paths
67
     *
68
     * @return Configuration
69
     */
70
    public function setExclusions(array $paths): Configuration
71
    {
72
        $this->exclusions = array_values($paths);
0 ignored issues
show
Documentation Bug introduced by
It seems like array_values($paths) of type array<integer,object<string>> is incompatible with the declared type array<integer,string> of property $exclusions.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
73
74
        return $this;
75
    }
76
77
    /**
78
     * @param string $path
79
     *
80
     * @return Configuration
81
     */
82
    public function addExclusion(string $path): Configuration
83
    {
84
        $this->exclusions[] = $path;
85
86
        return $this;
87
    }
88
89
    /**
90
     * @return string
91
     */
92
    public function getIdentity()
93
    {
94
        return $this->identity;
95
    }
96
97
    /**
98
     * @param string $identity
99
     *
100
     * @return Configuration
101
     */
102
    public function setIdentity(string $identity): Configuration
103
    {
104
        $this->identity = $identity;
105
106
        return $this;
107
    }
108
109
    /**
110
     * @return VaultConfiguration[]
111
     */
112
    public function getVaultConfigurations(): array
113
    {
114
        return $this->vaultConfigurations;
115
    }
116
117
    /**
118
     * @param string $title
119
     * @return bool
120
     */
121
    public function hasVaultConfiguration(string $title): bool
122
    {
123
        return isset($this->vaultConfigurations[$title]);
124
    }
125
126
    /**
127
     * @param string $title
128
     *
129
     * @return VaultConfiguration
130
     */
131
    public function getVaultConfigurationByTitle(string $title)
132
    {
133
        if (!isset($this->vaultConfigurations[$title]))
134
        {
135
            throw new \InvalidArgumentException("Unknown vault configuration requested: {$title}");
136
        }
137
138
        return $this->vaultConfigurations[$title];
139
    }
140
141
    /**
142
     * @param VaultConfiguration $configuration
143
     *
144
     * @return Configuration
145
     * @throws Exception
146
     */
147
    public function addVaultConfiguration(VaultConfiguration $configuration): Configuration
148
    {
149
        if (isset($this->vaultConfigurations[$configuration->getTitle()]))
150
        {
151
            throw new Exception(sprintf('Trying to add vault configration with duplicate title %s.', $configuration->getTitle()));
152
        }
153
154
        $this->vaultConfigurations[$configuration->getTitle()] = $configuration;
155
156
        return $this;
157
    }
158
}
159