Completed
Push — master ( 40b968...c8aec2 )
by Neomerx
12:32
created

Values::isRequired()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php namespace Limoncello\Validation\Validator;
2
3
/**
4
 * Copyright 2015-2016 [email protected] (www.neomerx.com)
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\MessageCodes;
20
use Limoncello\Validation\Contracts\RuleInterface;
21
use Limoncello\Validation\Rules\Between;
22
use Limoncello\Validation\Rules\CallableRule;
23
use Limoncello\Validation\Rules\RegExp;
24
use Limoncello\Validation\Rules\Required;
25
use Limoncello\Validation\Rules\StringLength;
26
27
/**
28
 * @package Limoncello\Validation
29
 */
30
trait Values
31
{
32
    /**
33
     * @return RuleInterface
34
     */
35 6
    protected static function isRequired()
36
    {
37 6
        return new Required();
38
    }
39
40
    /**
41
     * @return RuleInterface
42
     */
43 4
    protected static function isNull()
44
    {
45 4
        return new CallableRule('is_null', MessageCodes::IS_NULL);
46
    }
47
48
    /**
49
     * @return RuleInterface
50
     */
51
    protected static function notNull()
52
    {
53 4
        return new CallableRule(function ($input) {
54 4
            return $input !== null;
55 4
        }, MessageCodes::NOT_NULL);
56
    }
57
58
    /**
59
     * @param string $pattern
60
     *
61
     * @return RuleInterface
62
     */
63 1
    protected static function regExp($pattern)
64
    {
65 1
        return new RegExp($pattern);
66
    }
67
68
    /**
69
     * @param null|int $min
70
     * @param null|int $max
71
     *
72
     * @return RuleInterface
73
     */
74 3
    protected static function between($min = null, $max = null)
75
    {
76 3
        return new Between($min, $max);
77
    }
78
79
    /**
80
     * @param null|int $min
81
     * @param null|int $max
82
     *
83
     * @return RuleInterface
84
     */
85 7
    protected static function stringLength($min = null, $max = null)
86
    {
87 7
        return new StringLength($min, $max);
88
    }
89
}
90