| Total Complexity | 14 |
| Total Lines | 59 |
| Duplicated Lines | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 1 |
| 1 | <?php |
||
| 5 | trait Helper |
||
| 6 | { |
||
| 7 | protected static Validator $instance; |
||
| 8 | protected array $data = []; |
||
| 9 | protected array $validators = []; |
||
| 10 | protected string $model = ''; |
||
| 11 | protected array $required = []; |
||
| 12 | protected array $errors = []; |
||
| 13 | protected static string $lang = 'en'; |
||
| 14 | protected static array $err = []; |
||
| 15 | |||
| 16 | |||
| 17 | protected static function array($value): Array |
||
| 18 | { |
||
| 19 | return (is_array($value)) ? $value : [ $value ]; |
||
| 20 | } |
||
| 21 | |||
| 22 | protected static function getInstance(?string $lang = null): Validator |
||
| 23 | { |
||
| 24 | self::$lang = (null !== $lang) ? $lang : 'en'; |
||
| 25 | self::$instance = (isset(self::$instance)) ? self::$instance : new Validator(); |
||
| 26 | return self::$instance; |
||
| 27 | } |
||
| 28 | |||
| 29 | protected function error(array $error): void |
||
| 30 | { |
||
| 31 | $this->errors = array_merge($this->errors, $error); |
||
| 32 | } |
||
| 33 | |||
| 34 | protected function data($field = null, ?array $values = null) |
||
| 35 | { |
||
| 36 | if(null !== $values){ |
||
| 37 | $this->data[$field] = $values; |
||
| 38 | } |
||
| 39 | if(null !== $field){ |
||
| 40 | return $this->data[$field]; |
||
| 41 | } |
||
| 42 | return $this->data; |
||
| 43 | } |
||
| 44 | |||
| 45 | protected function validator(string $model, ?object $callback = null) |
||
| 46 | { |
||
| 47 | if(null !== $callback){ |
||
| 48 | $this->validators[$model] = $callback; |
||
| 49 | } |
||
| 50 | return $this->validators[$model]; |
||
| 51 | } |
||
| 52 | |||
| 53 | protected function model(?string $model = null): string |
||
| 54 | { |
||
| 55 | if(null !== $model){ |
||
| 56 | $this->model = $model; |
||
| 57 | } |
||
| 58 | return $this->model; |
||
| 59 | } |
||
| 60 | |||
| 61 | protected function required(): array |
||
| 64 | } |
||
| 65 | |||
| 66 | } |
||
| 67 |