Completed
Pull Request — master (#132)
by Albert
12:15 queued 02:49
created

DelegatedValidator::isImplicit()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 0
cts 0
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 2
1
<?php
2
3
namespace Proengsoft\JsValidation\Support;
4
5
use Closure;
6
use Illuminate\Validation\Validator as BaseValidator;
7
8
class DelegatedValidator
9
{
10
    use AccessProtectedTrait;
11
    /**
12
     * The Validator resolved instance.
13
     *
14
     * @var \Illuminate\Validation\Validator
15
     */
16
    protected $validator;
17
18
    /**
19
     *  Closure to invoke non accessible Validator methods.
20
     *
21
     * @var Closure
22
     */
23
    protected $validatorMethod;
24
25
    /**
26
     * DelegatedValidator constructor.
27
     * @param \Illuminate\Validation\Validator $validator
28
     */
29 16
    public function __construct(BaseValidator $validator)
30
    {
31 16
        $this->validator = $validator;
32 16
        $this->validatorMethod = $this->createProtectedCaller($validator);
33 16
    }
34
35 5
    /**
36
     * @param string $method
37 5
     */
38
    private function callValidator($method, $args = [])
39
    {
40
        return $this->callProtected($this->validatorMethod, $method, $args);
41
    }
42
43
    /**
44
     * Get current \Illuminate\Validation\Validator instance.
45 1
     *
46
     * @return \Illuminate\Validation\Validator
47 1
     */
48
    public function getValidator()
49
    {
50
        return $this->validator;
51
    }
52
53
    /**
54
     * Get the data under validation.
55 1
     *
56
     * @return array
57 1
     */
58
    public function getData()
59
    {
60
        return $this->validator->getData();
61
    }
62
63
    /**
64
     * Set the data under validation.
65 1
     *
66
     * @param array
67 1
     */
68 1
    public function setData($data)
69
    {
70
        $this->validator->setData($data);
71
    }
72
73
    /**
74
     * Get the validation rules.
75 1
     *
76
     * @return array
77 1
     */
78
    public function getRules()
79
    {
80
        return $this->validator->getRules();
81
    }
82
83
    /**
84
     * Get the files under validation.
85 1
     *
86
     * @return array
87 1
     */
88
    public function getFiles()
89
    {
90
        return $this->validator->getFiles();
91
    }
92
93
    /**
94
     * Set the files under validation.
95
     *
96
     * @param array $files
97 1
     *
98
     * @return BaseValidator
99 1
     */
100
    public function setFiles(array $files)
101
    {
102
        return $this->validator->setFiles($files);
103
    }
104
105
    /**
106
     * Determine if a given rule implies the attribute is required.
107
     *
108
     * @param string $rule
109 1
     *
110
     * @return bool
111 1
     */
112
    public function isImplicit($rule)
113
    {
114
        return $this->callValidator('isImplicit', [$rule]);
115
    }
116
117
    /**
118
     * Replace all error message place-holders with actual values.
119
     *
120
     * @param string $message
121
     * @param string $attribute
122
     * @param string $rule
123
     * @param array  $parameters
124 1
     *
125
     * @return string
126 1
     */
127
    public function doReplacements($message, $attribute, $rule, $parameters)
128
    {
129
        return $this->callValidator('doReplacements', [$message, $attribute, $rule, $parameters]);
130
    }
131
132
    /**
133
     * Determine if the given attribute has a rule in the given set.
134
     *
135
     * @param string       $attribute
136
     * @param string|array $rules
137 1
     *
138
     * @return bool
139 1
     */
140
    public function hasRule($attribute, $rules)
141
    {
142
        return $this->callValidator('hasRule', [$attribute, $rules]);
143
    }
144
145
    /**
146
     * Get the validation message for an attribute and rule.
147
     *
148
     * @param string $attribute
149
     * @param string $rule
150 1
     *
151
     * @return string
152 1
     */
153
    public function getMessage($attribute, $rule)
154
    {
155
        return $this->callValidator('getMessage', [$attribute, $rule]);
156
    }
157
158
    /**
159
     * Extract the rule name and parameters from a rule.
160
     *
161
     * @param array|string $rules
162 1
     *
163
     * @return array
164 1
     */
165
    public function parseRule($rules)
166
    {
167
        return $this->callValidator('parseRule', [$rules]);
168
    }
169
170
    /**
171
     * Explode the rules into an array of rules.
172
     *
173
     * @param  string|array  $rules
174
     * @return array
175 1
     */
176
    public function explodeRules($rules)
177 1
    {
178
        return $this->callValidator('explodeRules', [$rules]);
179 1
    }
180
181
    /**
182
     * Add conditions to a given field based on a Closure.
183
     *
184
     * @param  string  $attribute
185
     * @param  string|array  $rules
186
     * @param  callable  $callback
187
     * @return void
188
     */
189
    public function sometimes($attribute, $rules, callable $callback)
190
    {
191
        $this->validator->sometimes($attribute, $rules, $callback);
192
    }
193
194
    /**
195
     * Delegate method calls to validator instance.
196
     *
197
     * @param $method
198
     * @param $params
199
     *
200
     * @return mixed
201
     */
202
    public function __call($method, $params)
203
    {
204
        $arrCaller = array($this->validator, $method);
205
206
        return call_user_func_array($arrCaller, $params);
207
    }
208
}
209