Completed
Push — master ( 2e5d0e...583994 )
by Bartko
06:02
created

Options::setScopeColumnName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 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
    private $scopeColumnName = '';
18
19
    /**
20
     * @param array $options
21
     * @throws InvalidArgumentException
22
     */
23 127
    public function __construct(array $options)
24
    {
25
        $requiredOptions = array(
26 127
            'tableName', 'idColumnName',
27
        );
28
29 127
        $missingKeys = array_diff_key(array_flip($requiredOptions), $options);
30
31 127
        if (count($missingKeys)) {
32 1
            throw new InvalidArgumentException(implode(', ', array_flip($missingKeys))
33 1
                . ' must be set');
34
        }
35
36 126
        $this->setOptions($options);
37 126
    }
38
39
    /**
40
     * @param array $options
41
     * @return void
42
     */
43 126
    protected function setOptions($options)
44
    {
45 126
        foreach ($options as $name => $value) {
46 126
            $methodName = 'set' . ucfirst($name);
47 126
            if (method_exists($this, $methodName)) {
48 126
                $this->$methodName($value);
49
            }
50
        }
51 126
    }
52
53
    /**
54
     * @param string $tableName
55
     * @return void
56
     * @throws InvalidArgumentException
57
     */
58 126
    public function setTableName($tableName)
59
    {
60 126
        $tableName = (string) trim($tableName);
61
62 126
        if (empty($tableName)) {
63 1
            throw new InvalidArgumentException('tableName cannot be empty');
64
        }
65
66 126
        $this->tableName = $tableName;
67 126
    }
68
69
    /**
70
     * @return string
71
     */
72 109
    public function getTableName()
73
    {
74 109
        return $this->tableName;
75
    }
76
77
    /**
78
     * @param string $sequenceName
79
     * @return void
80
     */
81 1
    public function setSequenceName($sequenceName)
82
    {
83 1
        $this->sequenceName = (string) trim($sequenceName);
84 1
    }
85
86
    /**
87
     * @return string
88
     */
89 28
    public function getSequenceName()
90
    {
91 28
        return $this->sequenceName;
92
    }
93
94
    /**
95
     * @param string $idColumnName
96
     * @return void
97
     * @throws InvalidArgumentException
98
     */
99 126
    public function setIdColumnName($idColumnName)
100
    {
101 126
        $idColumnName = (string) trim($idColumnName);
102
103 126
        if (empty($idColumnName)) {
104 1
            throw new InvalidArgumentException('idColumnName cannot be empty');
105
        }
106
107 126
        $this->idColumnName = $idColumnName;
108 126
    }
109
110
    /**
111
     * @return string
112
     */
113 79
    public function getIdColumnName()
114
    {
115 79
        return $this->idColumnName;
116
    }
117
118
    /**
119
     * @param string $leftColumnName
120
     * @return void
121
     * @throws InvalidArgumentException
122
     */
123 2
    public function setLeftColumnName($leftColumnName)
124
    {
125 2
        $leftColumnName = (string) trim($leftColumnName);
126
127 2
        if (empty($leftColumnName)) {
128 1
            throw new InvalidArgumentException('leftColumnName cannot be empty');
129
        }
130
131 1
        $this->leftColumnName = $leftColumnName;
132 1
    }
133
134
    /**
135
     * @return string
136
     */
137 85
    public function getLeftColumnName()
138
    {
139 85
        return $this->leftColumnName;
140
    }
141
142
    /**
143
     * @param string $rightColumnName
144
     * @return void
145
     * @throws InvalidArgumentException
146
     */
147 2
    public function setRightColumnName($rightColumnName)
148
    {
149 2
        $rightColumnName = (string) trim($rightColumnName);
150
151 2
        if (empty($rightColumnName)) {
152 1
            throw new InvalidArgumentException('rightColumnName cannot be empty');
153
        }
154
155 1
        $this->rightColumnName = $rightColumnName;
156 1
    }
157
158
    /**
159
     * @return string
160
     */
161 85
    public function getRightColumnName()
162
    {
163 85
        return $this->rightColumnName;
164
    }
165
166
    /**
167
     * @param string $levelColumnName
168
     * @return void
169
     * @throws InvalidArgumentException
170
     */
171 2
    public function setLevelColumnName($levelColumnName)
172
    {
173 2
        $levelColumnName = (string) trim($levelColumnName);
174
175 2
        if (empty($levelColumnName)) {
176 1
            throw new InvalidArgumentException('levelColumnName cannot be empty');
177
        }
178
179 1
        $this->levelColumnName = $levelColumnName;
180 1
    }
181
182
    /**
183
     * @return string
184
     */
185 85
    public function getLevelColumnName()
186
    {
187 85
        return $this->levelColumnName;
188
    }
189
190
    /**
191
     * @param string $parentIdColumnName
192
     * @return void
193
     * @throws InvalidArgumentException
194
     */
195 2
    public function setParentIdColumnName($parentIdColumnName)
196
    {
197 2
        $parentIdColumnName = (string) trim($parentIdColumnName);
198
199 2
        if (empty($parentIdColumnName)) {
200 1
            throw new InvalidArgumentException('parentIdColumnName cannot be empty');
201
        }
202
203 1
        $this->parentIdColumnName = $parentIdColumnName;
204 1
    }
205
206
    /**
207
     * @return string
208
     */
209 97
    public function getParentIdColumnName()
210
    {
211 97
        return $this->parentIdColumnName;
212
    }
213
214
    /**
215
     * @param $scopeColumnName
216
     */
217 40
    public function setScopeColumnName($scopeColumnName)
218
    {
219 40
        $this->scopeColumnName = trim($scopeColumnName);
220 40
    }
221
222
    /**
223
     * @return string
224
     */
225 86
    public function getScopeColumnName()
226
    {
227 86
        return $this->scopeColumnName;
228
    }
229
}
230