Completed
Branch master (a1edd4)
by
unknown
54:09
created

DateValidator::isEmpty()   B

Complexity

Conditions 6
Paths 6

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 8.8571
c 0
b 0
f 0
cc 6
eloc 5
nc 6
nop 1
1
<?php
2
/**
3
 * This file is part of the fangface/yii2-concord package
4
 *
5
 * For the full copyright and license information, please view
6
 * the file LICENSE.md that was distributed with this source code.
7
 *
8
 * @package fangface/yii2-concord
9
 * @author Fangface <[email protected]>
10
 * @copyright Copyright (c) 2014 Fangface <[email protected]>
11
 * @license https://github.com/fangface/yii2-concord/blob/master/LICENSE.md MIT License
12
 *
13
 */
14
15
namespace fangface\validators;
16
17
use yii\validators\DateValidator as YiiDateValidator;
18
use fangface\Tools;
19
20
/**
21
 * DateValidator extends default to allow for non validation of empty dates
22
 *
23
 * @author Fangface
24
 */
25
class DateValidator extends YiiDateValidator
26
{
27
    /**
28
     * Checks if the given value is empty.
29
     * A value is considered empty if it is null, an empty array, or an empty string.
30
     * We also treat some dates e.g. 0000-00-00 as empty
31
     * Note that this method is different from PHP empty(). It will return false when the value is 0.
32
     * @param mixed $value the value to be checked
33
     * @return boolean whether the value is empty
34
     */
35
    public function isEmpty($value)
36
    {
37
        if ($this->isEmpty !== null) {
38
            return call_user_func($this->isEmpty, $value);
39
        } else {
40
            return $value === null || $value === [] || $value === '' || $value === Tools::DATE_TIME_DB_EMPTY || $value === Tools::DATE_DB_EMPTY;
41
        }
42
    }
43
44
}
45