Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
Total | |
0.00% |
0 / 1 |
|
50.00% |
1 / 2 |
CRAP | |
88.89% |
8 / 9 |
AbstractRule | |
0.00% |
0 / 1 |
|
50.00% |
1 / 2 |
4.02 | |
88.89% |
8 / 9 |
passes | |
0.00% |
0 / 1 |
3.02 | |
87.50% |
7 / 8 |
|||
message | |
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
1 | <?php |
2 | |
3 | |
4 | namespace Qmp\Laravel\Geolocation\Services\Validations\Rules; |
5 | |
6 | |
7 | use Illuminate\Contracts\Validation\Rule; |
8 | |
9 | abstract class AbstractRule implements Rule |
10 | { |
11 | |
12 | protected $errors = []; |
13 | |
14 | protected $methods = []; |
15 | |
16 | protected $isValid = false; |
17 | |
18 | |
19 | /** |
20 | * Check if rule passe |
21 | * |
22 | * @param string $attribute |
23 | * @param mixed $value |
24 | * @return bool |
25 | */ |
26 | public function passes($attribute, $value) |
27 | { |
28 | collect($value)->map(function($entry) { |
29 | foreach ($this->methods as $method) { |
30 | $method = 'validate' . ucfirst($method); |
31 | if(!method_exists($this, $method)) { |
32 | throw new \Exception($method . ' not exists ' . 'in ' . get_called_class()); |
33 | } |
34 | |
35 | $this->$method($entry); |
36 | } |
37 | }); |
38 | |
39 | return empty($this->errors); |
40 | } |
41 | |
42 | /** |
43 | * Return errors messages |
44 | * |
45 | * @return array|string |
46 | */ |
47 | public function message() |
48 | { |
49 | return implode(' ', $this->errors); |
50 | } |
51 | |
52 | |
53 | } |