Completed
Push — master ( 71ec50...18d3f1 )
by Albert
02:10
created

RuleListTrait::isDisableRule()   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 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Proengsoft\JsValidation\Support;
4
5
trait RuleListTrait
6
{
7
    /**
8
     *  Rules validated with Javascript.
9
     *
10
     * @var array
11
     */
12
    protected $clientRules = ['Accepted', 'After', 'Alpha', 'AlphaDash',
13
        'AlphaNum', 'Array', 'Before', 'Between', 'Boolean', 'Confirmed', 'Date',
14
        'DateFormat', 'Different', 'Digits', 'DigitsBetween', 'Email', 'Image',
15
        'In', 'Integer', 'Ip', 'Json', 'Max', 'Mimes', 'Min', 'NotIn', 'Numeric',
16
        'Regex', 'Required', 'RequiredIf', 'RequiredWith', 'RequiredWithAll',
17
        'RequiredWithout', 'RequiredWithoutAll', 'Same', 'Size', 'Sometimes',
18
        'String', 'Timezone', 'Url', ];
19
20
    /**
21
     * Rules validated in Server-Side.
22
     *
23
     * @var array
24
     */
25
    protected $serverRules = ['ActiveUrl', 'Exists', 'Unique'];
26
27
    /**
28
     * Rules applyed to files.
29
     *
30
     * @var array
31
     */
32
    protected $fileRules = ['Image', 'Mimes'];
33
34
    /**
35
     * Rule used to disable validations.
36
     *
37
     * @var string
38
     */
39
    private $disableJsValidationRule = 'NoJsValidation';
40
41
    /**
42
     * Returns if rule is validated using Javascript.
43
     *
44
     * @param $rule
45
     *
46
     * @return bool
47
     */
48 1
    protected function isImplemented($rule)
49
    {
50 1
        return in_array($rule, $this->clientRules) || in_array($rule, $this->serverRules);
51
    }
52
53
    /**
54
     * Check if rule must be validated in server-side.
55
     *
56
     * @param $rule
57
     *
58
     * @return bool
59
     */
60 9
    protected function isRemoteRule($rule)
61
    {
62 9
        return in_array($rule, $this->serverRules) ||
63 9
            ! in_array($rule, $this->clientRules);
64
    }
65
66
    /**
67
     * Check if rule disables rule processing.
68
     *
69
     * @param $rule
70
     *
71
     * @return bool
72
     */
73 1
    protected function isDisableRule($rule)
74
    {
75 1
        return $rule === $this->disableJsValidationRule;
76
    }
77
78
    /**
79
     * Check if rules should be validated.
80
     *
81
     * @param $rules
82
     *
83
     * @return bool
84
     */
85 5
    protected function validationDisabled($rules)
86
    {
87 5
        $rules = (array) $rules;
88
89 5
        return in_array($this->disableJsValidationRule, $rules);
90
    }
91
92
    /**
93
     * Check if rules is for input file type.
94
     *
95
     * @param $rule
96
     
97
     * @return bool
98
     */
99 1
    protected function isFileRule($rule)
100
    {
101 1
        return in_array($rule, $this->fileRules);
102
    }
103
}
104