Completed
Push — develop ( 4ea5a3...a8c617 )
by Bartko
05:56
created

Options   A

Complexity

Total Complexity 25

Size/Duplication

Total Lines 207
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 5
Bugs 2 Features 0
Metric Value
wmc 25
c 5
b 2
f 0
lcom 1
cbo 1
dl 0
loc 207
ccs 70
cts 70
cp 1
rs 10

16 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 15 2
A setOptions() 0 9 3
A setTableName() 0 10 2
A getTableName() 0 4 1
A setSequenceName() 0 4 1
A getSequenceName() 0 4 1
A setIdColumnName() 0 10 2
A getIdColumnName() 0 4 1
A setLeftColumnName() 0 10 2
A getLeftColumnName() 0 4 1
A setRightColumnName() 0 10 2
A getRightColumnName() 0 4 1
A setLevelColumnName() 0 10 2
A getLevelColumnName() 0 4 1
A setParentIdColumnName() 0 10 2
A getParentIdColumnName() 0 4 1
1
<?php
2
namespace StefanoTree\NestedSet;
3
4
use StefanoTree\Exception\InvalidArgumentException;
5
6
class Options
7
{
8
    private $tableName = null;
9
10
    private $sequenceName = '';
11
12
    private $idColumnName = null;
13
    private $leftColumnName = 'lft';
14
    private $rightColumnName = 'rgt';
15
    private $levelColumnName = 'level';
16
    private $parentIdColumnName = 'parent_id';
17
18
    /**
19
     * @param array $options
20
     * @throws InvalidArgumentException
21
     */
22 74
    public function __construct(array $options)
23
    {
24
        $requiredOptions = array(
25 74
            'tableName', 'idColumnName',
26 74
        );
27
28 74
        $missingKeys = array_diff_key(array_flip($requiredOptions), $options);
29
30 74
        if (count($missingKeys)) {
31 1
            throw new InvalidArgumentException(implode(', ', array_flip($missingKeys))
32 1
                . ' must be set');
33
        }
34
35 73
        $this->setOptions($options);
36 73
    }
37
38
    /**
39
     * @param array $options
40
     * @return void
41
     */
42 73
    protected function setOptions($options)
43
    {
44 73
        foreach ($options as $name => $value) {
45 73
            $methodName = 'set' . ucfirst($name);
46 73
            if (method_exists($this, $methodName)) {
47 73
                $this->$methodName($value);
48 73
            }
49 73
        }
50 73
    }
51
52
    /**
53
     * @param string $tableName
54
     * @return void
55
     * @throws InvalidArgumentException
56
     */
57 73
    public function setTableName($tableName)
58
    {
59 73
        $tableName = (string) trim($tableName);
60
61 73
        if (empty($tableName)) {
62 1
            throw new InvalidArgumentException('tableName cannot be empty');
63
        }
64
65 73
        $this->tableName = $tableName;
66 73
    }
67
68
    /**
69
     * @return string
70
     */
71 58
    public function getTableName()
72
    {
73 58
        return $this->tableName;
74
    }
75
76
    /**
77
     * @param string $sequenceName
78
     * @return void
79
     */
80 52
    public function setSequenceName($sequenceName)
81
    {
82 52
        $this->sequenceName = (string) trim($sequenceName);
83 52
    }
84
85
    /**
86
     * @return string
87
     */
88 13
    public function getSequenceName()
89
    {
90 13
        return $this->sequenceName;
91
    }
92
93
    /**
94
     * @param string $idColumnName
95
     * @return void
96
     * @throws InvalidArgumentException
97
     */
98 73
    public function setIdColumnName($idColumnName)
99
    {
100 73
        $idColumnName = (string) trim($idColumnName);
101
102 73
        if (empty($idColumnName)) {
103 1
            throw new InvalidArgumentException('idColumnName cannot be empty');
104
        }
105
106 73
        $this->idColumnName = $idColumnName;
107 73
    }
108
109
    /**
110
     * @return string
111
     */
112 52
    public function getIdColumnName()
113
    {
114 52
        return $this->idColumnName;
115
    }
116
117
    /**
118
     * @param string $leftColumnName
119
     * @return void
120
     * @throws InvalidArgumentException
121
     */
122 2
    public function setLeftColumnName($leftColumnName)
123
    {
124 2
        $leftColumnName = (string) trim($leftColumnName);
125
126 2
        if (empty($leftColumnName)) {
127 1
            throw new InvalidArgumentException('leftColumnName cannot be empty');
128
        }
129
130 1
        $this->leftColumnName = $leftColumnName;
131 1
    }
132
133
    /**
134
     * @return string
135
     */
136 46
    public function getLeftColumnName()
137
    {
138 46
        return $this->leftColumnName;
139
    }
140
141
    /**
142
     * @param string $rightColumnName
143
     * @return void
144
     * @throws InvalidArgumentException
145
     */
146 2
    public function setRightColumnName($rightColumnName)
147
    {
148 2
        $rightColumnName = (string) trim($rightColumnName);
149
150 2
        if (empty($rightColumnName)) {
151 1
            throw new InvalidArgumentException('rightColumnName cannot be empty');
152
        }
153
154 1
        $this->rightColumnName = $rightColumnName;
155 1
    }
156
157
    /**
158
     * @return string
159
     */
160 46
    public function getRightColumnName()
161
    {
162 46
        return $this->rightColumnName;
163
    }
164
165
    /**
166
     * @param string $levelColumnName
167
     * @return void
168
     * @throws InvalidArgumentException
169
     */
170 2
    public function setLevelColumnName($levelColumnName)
171
    {
172 2
        $levelColumnName = (string) trim($levelColumnName);
173
174 2
        if (empty($levelColumnName)) {
175 1
            throw new InvalidArgumentException('levelColumnName cannot be empty');
176
        }
177
178 1
        $this->levelColumnName = $levelColumnName;
179 1
    }
180
181
    /**
182
     * @return string
183
     */
184 46
    public function getLevelColumnName()
185
    {
186 46
        return $this->levelColumnName;
187
    }
188
189
    /**
190
     * @param string $parentIdColumnName
191
     * @return void
192
     * @throws InvalidArgumentException
193
     */
194 2
    public function setParentIdColumnName($parentIdColumnName)
195
    {
196 2
        $parentIdColumnName = (string) trim($parentIdColumnName);
197
198 2
        if (empty($parentIdColumnName)) {
199 1
            throw new InvalidArgumentException('parentIdColumnName cannot be empty');
200
        }
201
202 1
        $this->parentIdColumnName = $parentIdColumnName;
203 1
    }
204
205
    /**
206
     * @return string
207
     */
208 46
    public function getParentIdColumnName()
209
    {
210 46
        return $this->parentIdColumnName;
211
    }
212
}
213