Completed
Push — master ( cb7793...7b1e0a )
by Arne
01:36
created

Configuration::addExclusion()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
namespace Archivr;
4
5
use Archivr\Exception\Exception;
6
7
class Configuration
8
{
9
    /**
10
     * @var string
11
     */
12
    protected $localPath;
13
14
    /**
15
     * @var string[]
16
     */
17
    protected $exclusions = [];
18
19
    /**
20
     * @var string
21
     */
22
    protected $identity;
23
24
    /**
25
     * @var ConnectionConfiguration[]
26
     */
27
    protected $connectionConfigurations = [];
28
29
    /**
30
     * @return string
31
     */
32
    public function getLocalPath(): string
33
    {
34
        return $this->localPath;
35
    }
36
37
    /**
38
     * @param string $localPath
39
     *
40
     * @return Configuration
41
     */
42
    public function setLocalPath(string $localPath): Configuration
43
    {
44
        $this->localPath = $localPath;
45
46
        return $this;
47
    }
48
49
    /**
50
     * @return \string[]
51
     */
52
    public function getExclusions(): array
53
    {
54
        return $this->exclusions;
55
    }
56
57
    /**
58
     * @param \string[] $paths
59
     *
60
     * @return Configuration
61
     */
62
    public function setExclusions(array $paths): Configuration
63
    {
64
        $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...
65
66
        return $this;
67
    }
68
69
    /**
70
     * @param string $path
71
     *
72
     * @return Configuration
73
     */
74
    public function addExclusion(string $path): Configuration
75
    {
76
        $this->exclusions[] = $path;
77
78
        return $this;
79
    }
80
81
    /**
82
     * @return string
83
     */
84
    public function getIdentity()
85
    {
86
        return $this->identity;
87
    }
88
89
    /**
90
     * @param string $identity
91
     *
92
     * @return Configuration
93
     */
94
    public function setIdentity(string $identity): Configuration
95
    {
96
        $this->identity = $identity;
97
98
        return $this;
99
    }
100
101
    /**
102
     * @return ConnectionConfiguration[]
103
     */
104
    public function getConnectionConfigurations(): array
105
    {
106
        return $this->connectionConfigurations;
107
    }
108
109
    /**
110
     * @param string $title
111
     *
112
     * @return ConnectionConfiguration
113
     */
114
    public function getConnectionConfigurationByTitle(string $title)
115
    {
116
        return isset($this->connectionConfigurations[$title]) ? $this->connectionConfigurations[$title] : null;
117
    }
118
119
    /**
120
     * @param ConnectionConfiguration[] $connectionConfigurations
121
     *
122
     * @return Configuration
123
     */
124
    public function setConnectionConfigurations(array $connectionConfigurations): Configuration
125
    {
126
        $this->connectionConfigurations = [];
127
128
        foreach ($connectionConfigurations as $connectionConfiguration)
129
        {
130
            $this->addConnectionConfiguration($connectionConfiguration);
131
        }
132
133
        return $this;
134
    }
135
136
    /**
137
     * @param ConnectionConfiguration $configuration
138
     *
139
     * @return Configuration
140
     * @throws Exception
141
     */
142
    public function addConnectionConfiguration(ConnectionConfiguration $configuration): Configuration
143
    {
144
        if (isset($this->connectionConfigurations[$configuration->getTitle()]))
145
        {
146
            throw new Exception(sprintf('Trying to add connection configration with duplicate title %s.', $configuration->getTitle()));
147
        }
148
149
        $this->connectionConfigurations[$configuration->getTitle()] = $configuration;
150
151
        return $this;
152
    }
153
}
154