Passed
Pull Request — master (#4240)
by Owen
18:54 queued 08:08
created

DataValidation::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 0
nc 1
nop 0
dl 0
loc 2
ccs 1
cts 1
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace PhpOffice\PhpSpreadsheet\Cell;
4
5
class DataValidation
6
{
7
    // Data validation types
8
    const TYPE_NONE = 'none';
9
    const TYPE_CUSTOM = 'custom';
10
    const TYPE_DATE = 'date';
11
    const TYPE_DECIMAL = 'decimal';
12
    const TYPE_LIST = 'list';
13
    const TYPE_TEXTLENGTH = 'textLength';
14
    const TYPE_TIME = 'time';
15
    const TYPE_WHOLE = 'whole';
16
17
    // Data validation error styles
18
    const STYLE_STOP = 'stop';
19
    const STYLE_WARNING = 'warning';
20
    const STYLE_INFORMATION = 'information';
21
22
    // Data validation operators
23
    const OPERATOR_BETWEEN = 'between';
24
    const OPERATOR_EQUAL = 'equal';
25
    const OPERATOR_GREATERTHAN = 'greaterThan';
26
    const OPERATOR_GREATERTHANOREQUAL = 'greaterThanOrEqual';
27
    const OPERATOR_LESSTHAN = 'lessThan';
28
    const OPERATOR_LESSTHANOREQUAL = 'lessThanOrEqual';
29
    const OPERATOR_NOTBETWEEN = 'notBetween';
30
    const OPERATOR_NOTEQUAL = 'notEqual';
31
    private const DEFAULT_OPERATOR = self::OPERATOR_BETWEEN;
32
33
    /**
34
     * Formula 1.
35
     */
36
    private string $formula1 = '';
37
38
    /**
39
     * Formula 2.
40
     */
41
    private string $formula2 = '';
42
43
    /**
44
     * Type.
45
     */
46
    private string $type = self::TYPE_NONE;
47
48
    /**
49
     * Error style.
50
     */
51
    private string $errorStyle = self::STYLE_STOP;
52
53
    /**
54
     * Operator.
55
     */
56
    private string $operator = self::DEFAULT_OPERATOR;
57
58
    /**
59
     * Allow Blank.
60
     */
61
    private bool $allowBlank = false;
62
63
    /**
64
     * Show DropDown.
65
     */
66
    private bool $showDropDown = false;
67
68
    /**
69
     * Show InputMessage.
70
     */
71
    private bool $showInputMessage = false;
72
73
    /**
74
     * Show ErrorMessage.
75
     */
76
    private bool $showErrorMessage = false;
77
78
    /**
79
     * Error title.
80
     */
81
    private string $errorTitle = '';
82
83
    /**
84
     * Error.
85
     */
86
    private string $error = '';
87
88
    /**
89
     * Prompt title.
90
     */
91
    private string $promptTitle = '';
92
93
    /**
94
     * Prompt.
95
     */
96
    private string $prompt = '';
97
98
    /**
99
     * Get Formula 1.
100
     */
101 36
    public function getFormula1(): string
102
    {
103 36
        return $this->formula1;
104
    }
105
106
    /**
107
     * Set Formula 1.
108
     *
109
     * @return $this
110
     */
111 43
    public function setFormula1(string $formula): static
112
    {
113 43
        $this->formula1 = $formula;
114
115 43
        return $this;
116
    }
117
118
    /**
119
     * Get Formula 2.
120
     */
121 25
    public function getFormula2(): string
122
    {
123 25
        return $this->formula2;
124
    }
125
126
    /**
127
     * Set Formula 2.
128
     *
129
     * @return $this
130
     */
131 27
    public function setFormula2(string $formula): static
132
    {
133 27
        $this->formula2 = $formula;
134
135 27
        return $this;
136
    }
137
138
    /**
139
     * Get Type.
140
     */
141 32
    public function getType(): string
142
    {
143 32
        return $this->type;
144
    }
145
146
    /**
147
     * Set Type.
148
     *
149
     * @return $this
150
     */
151 45
    public function setType(string $type): static
152
    {
153 45
        $this->type = $type;
154
155 45
        return $this;
156
    }
157
158
    /**
159
     * Get Error style.
160
     */
161 17
    public function getErrorStyle(): string
162
    {
163 17
        return $this->errorStyle;
164
    }
165
166
    /**
167
     * Set Error style.
168
     *
169
     * @param string $errorStyle see self::STYLE_*
170
     *
171
     * @return $this
172
     */
173 37
    public function setErrorStyle(string $errorStyle): static
174
    {
175 37
        $this->errorStyle = $errorStyle;
176
177 37
        return $this;
178
    }
179
180
    /**
181
     * Get Operator.
182
     */
183 22
    public function getOperator(): string
184
    {
185 22
        return $this->operator;
186
    }
187
188
    /**
189
     * Set Operator.
190
     *
191
     * @return $this
192
     */
193 27
    public function setOperator(string $operator): static
194
    {
195 27
        $this->operator = ($operator === '') ? self::DEFAULT_OPERATOR : $operator;
196
197 27
        return $this;
198
    }
199
200
    /**
201
     * Get Allow Blank.
202
     */
203 25
    public function getAllowBlank(): bool
204
    {
205 25
        return $this->allowBlank;
206
    }
207
208
    /**
209
     * Set Allow Blank.
210
     *
211
     * @return $this
212
     */
213 36
    public function setAllowBlank(bool $allowBlank): static
214
    {
215 36
        $this->allowBlank = $allowBlank;
216
217 36
        return $this;
218
    }
219
220
    /**
221
     * Get Show DropDown.
222
     */
223 17
    public function getShowDropDown(): bool
224
    {
225 17
        return $this->showDropDown;
226
    }
227
228
    /**
229
     * Set Show DropDown.
230
     *
231
     * @return $this
232
     */
233 38
    public function setShowDropDown(bool $showDropDown): static
234
    {
235 38
        $this->showDropDown = $showDropDown;
236
237 38
        return $this;
238
    }
239
240
    /**
241
     * Get Show InputMessage.
242
     */
243 16
    public function getShowInputMessage(): bool
244
    {
245 16
        return $this->showInputMessage;
246
    }
247
248
    /**
249
     * Set Show InputMessage.
250
     *
251
     * @return $this
252
     */
253 34
    public function setShowInputMessage(bool $showInputMessage): static
254
    {
255 34
        $this->showInputMessage = $showInputMessage;
256
257 34
        return $this;
258
    }
259
260
    /**
261
     * Get Show ErrorMessage.
262
     */
263 17
    public function getShowErrorMessage(): bool
264
    {
265 17
        return $this->showErrorMessage;
266
    }
267
268
    /**
269
     * Set Show ErrorMessage.
270
     *
271
     * @return $this
272
     */
273 38
    public function setShowErrorMessage(bool $showErrorMessage): static
274
    {
275 38
        $this->showErrorMessage = $showErrorMessage;
276
277 38
        return $this;
278
    }
279
280
    /**
281
     * Get Error title.
282
     */
283 16
    public function getErrorTitle(): string
284
    {
285 16
        return $this->errorTitle;
286
    }
287
288
    /**
289
     * Set Error title.
290
     *
291
     * @return $this
292
     */
293 37
    public function setErrorTitle(string $errorTitle): static
294
    {
295 37
        $this->errorTitle = $errorTitle;
296
297 37
        return $this;
298
    }
299
300
    /**
301
     * Get Error.
302
     */
303 16
    public function getError(): string
304
    {
305 16
        return $this->error;
306
    }
307
308
    /**
309
     * Set Error.
310
     *
311
     * @return $this
312
     */
313 37
    public function setError(string $error): static
314
    {
315 37
        $this->error = $error;
316
317 37
        return $this;
318
    }
319
320
    /**
321
     * Get Prompt title.
322
     */
323 16
    public function getPromptTitle(): string
324
    {
325 16
        return $this->promptTitle;
326
    }
327
328
    /**
329
     * Set Prompt title.
330
     *
331
     * @return $this
332
     */
333 32
    public function setPromptTitle(string $promptTitle): static
334
    {
335 32
        $this->promptTitle = $promptTitle;
336
337 32
        return $this;
338
    }
339
340
    /**
341
     * Get Prompt.
342
     */
343 16
    public function getPrompt(): string
344
    {
345 16
        return $this->prompt;
346
    }
347
348
    /**
349
     * Set Prompt.
350
     *
351
     * @return $this
352
     */
353 32
    public function setPrompt(string $prompt): static
354
    {
355 32
        $this->prompt = $prompt;
356
357 32
        return $this;
358
    }
359
360
    /**
361
     * Get hash code.
362
     *
363
     * @return string Hash code
364
     */
365 1
    public function getHashCode(): string
366
    {
367 1
        return md5(
368 1
            $this->formula1
369 1
            . $this->formula2
370 1
            . $this->type
371 1
            . $this->errorStyle
372 1
            . $this->operator
373 1
            . ($this->allowBlank ? 't' : 'f')
374 1
            . ($this->showDropDown ? 't' : 'f')
375 1
            . ($this->showInputMessage ? 't' : 'f')
376 1
            . ($this->showErrorMessage ? 't' : 'f')
377 1
            . $this->errorTitle
378 1
            . $this->error
379 1
            . $this->promptTitle
380 1
            . $this->prompt
381 1
            . $this->sqref
382 1
            . __CLASS__
383 1
        );
384
    }
385
386
    private ?string $sqref = null;
387
388 22
    public function getSqref(): ?string
389
    {
390 22
        return $this->sqref;
391
    }
392
393 44
    public function setSqref(?string $str): self
394
    {
395 44
        $this->sqref = $str;
396
397 44
        return $this;
398
    }
399
}
400