Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
0.00% covered (danger)
0.00%
0 / 1
50.00% covered (warning)
50.00%
1 / 2
CRAP
88.89% covered (success)
88.89%
8 / 9
AbstractRule
0.00% covered (danger)
0.00%
0 / 1
50.00% covered (warning)
50.00%
1 / 2
4.02
88.89% covered (success)
88.89%
8 / 9
 passes
0.00% covered (danger)
0.00%
0 / 1
3.02
87.50% covered (success)
87.50%
7 / 8
 message
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
1<?php
2
3
4namespace Qmp\Laravel\Geolocation\Services\Validations\Rules;
5
6
7use Illuminate\Contracts\Validation\Rule;
8
9abstract 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}