Completed
Push — master ( ceaad2...5caa52 )
by Neomerx
04:27 queued 01:12
created

Compares::equals()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 9.4285
nc 1
cc 1
eloc 4
nop 1
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\CallableRule;
22
23
/**
24
 * @package Limoncello\Validation
25
 */
26
trait Compares
27
{
28
    /**
29
     * @param mixed $value
30
     *
31
     * @return RuleInterface
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use CallableRule.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
32
     */
33 5
    protected static function equals($value)
34
    {
35
        return new CallableRule(function ($input) use ($value) {
36 5
            return $input === $value;
37 5
        }, MessageCodes::EQUALS);
38
    }
39
40
    /**
41
     * @param mixed $value
42
     *
43
     * @return RuleInterface
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use CallableRule.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
44
     */
45 1
    protected static function notEquals($value)
46
    {
47
        return new CallableRule(function ($input) use ($value) {
48 1
            return $input !== $value;
49 1
        }, MessageCodes::NOT_EQUALS);
50
    }
51
52
    /**
53
     * @param mixed $value
54
     *
55
     * @return RuleInterface
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use CallableRule.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
56
     */
57 1
    protected static function lessThan($value)
58
    {
59
        return new CallableRule(function ($input) use ($value) {
60 1
            return $input < $value;
61 1
        }, MessageCodes::LESS_THAN);
62
    }
63
64
    /**
65
     * @param mixed $value
66
     *
67
     * @return RuleInterface
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use CallableRule.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
68
     */
69 1
    protected static function lessOrEquals($value)
70
    {
71
        return new CallableRule(function ($input) use ($value) {
72 1
            return $input <= $value;
73 1
        }, MessageCodes::LESS_OR_EQUALS);
74
    }
75
76
    /**
77
     * @param mixed $value
78
     *
79
     * @return RuleInterface
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use CallableRule.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
80
     */
81 1
    protected static function moreThan($value)
82
    {
83
        return new CallableRule(function ($input) use ($value) {
84 1
            return $input > $value;
85 1
        }, MessageCodes::MORE_THAN);
86
    }
87
88
    /**
89
     * @param mixed $value
90
     *
91
     * @return RuleInterface
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use CallableRule.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
92
     */
93
    protected static function moreOrEquals($value)
94
    {
95 1
        return new CallableRule(function ($input) use ($value) {
96 1
            return $input >= $value;
97 1
        }, MessageCodes::MORE_OR_EQUALS);
98
    }
99
}
100