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

DateValidator   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 1
dl 0
loc 20
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B isEmpty() 0 8 6
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