Completed
Push — master ( 69572d...c5166f )
by Neomerx
05:53 queued 10s
created

Rules::isEmpty()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 2
crap 1
1
<?php namespace Limoncello\Validation;
2
3
/**
4
 * Copyright 2015-2017 [email protected]
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at
9
 *
10
 * http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * See the License for the specific language governing permissions and
16
 * limitations under the License.
17
 */
18
19
use Limoncello\Validation\Contracts\Execution\ContextInterface;
20
use Limoncello\Validation\Validator\Comparisons;
21
use Limoncello\Validation\Validator\Converters;
22
use Limoncello\Validation\Validator\Generics;
23
use Limoncello\Validation\Validator\Types;
24
25
/**
26
 * @package Limoncello\Validation
27
 */
28
class Rules
29
{
30
    /**
31
     * Callable for using in `ifX`.
32
     */
33
    public const IS_NULL_CALLABLE = [self::class, 'isNull'];
34
35
    /**
36
     * Callable for using in `ifX`.
37
     */
38
    public const IS_EMPTY_CALLABLE = [self::class, 'isEmpty'];
39
40
    use Comparisons {
41
        equals as public;
42
        notEquals as public;
43
        inValues as public;
44
        lessThan as public;
45
        lessOrEquals as public;
46
        moreThan as public;
47
        moreOrEquals as public;
48
        between as public;
49
        stringLengthBetween as public;
50
        stringLengthMin as public;
51
        stringLengthMax as public;
52
        regexp as public;
53
        nullable as public;
54
    }
55
56
    use Converters {
57
        stringToBool as public;
58
        stringToDateTime as public;
59
        stringToFloat as public;
60
        stringToInt as public;
61
        stringArrayToIntArray as public;
62
    }
63
64
    use Generics {
65
        andX as public;
66
        orX as public;
67
        ifX as public;
68
        success as public;
69
        fail as public;
70
        value as public;
71
        required as public;
72
        enum as public;
73
        filter as public;
74
    }
75
76
    use Types {
77
        isArray as public;
78
        isString as public;
79
        isBool as public;
80
        isInt as public;
81
        isFloat as public;
82
        isNumeric as public;
83
        isDateTime as public;
84
    }
85
86
    /**
87
     * @param mixed            $value
88
     * @param ContextInterface $context
89
     *
90
     * @return bool
91
     */
92 1
    public static function isNull($value, ContextInterface $context): bool
93
    {
94 1
        assert($context);
95
96 1
        return $value === null;
97
    }
98
99
    /**
100
     * @param mixed            $value
101
     * @param ContextInterface $context
102
     *
103
     * @return bool
104
     */
105 1
    public static function isEmpty($value, ContextInterface $context): bool
106
    {
107 1
        assert($context);
108
109 1
        return empty($value);
110
    }
111
}
112