Rules   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
c 1
b 0
f 0
dl 0
loc 33
rs 10
wmc 7

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A getRules() 0 3 2
A field() 0 10 3
A action() 0 4 1
1
<?php
2
3
namespace HnrAzevedo\Validator;
4
5
Class Rules
6
{
7
    use Helper;
8
9
    private string $action;
10
    private array $form = array();
11
12
    public function __construct(string $model)
13
    {
14
	    $this->form['model'] = ucfirst($model);
15
	}
16
17
    public function action(string $action): Rules
18
    {
19
	    $this->action = $action;
20
	    return $this;
21
	}
22
23
    public function field(string $field, array $test, ?string $placeholder = null): Rules
24
    {
25
	    if(empty($this->action)){
26
            $this->error([ 'form' => self::$err['nFoundForm'] ]);
27
            return $this;
28
        }
29
30
        $this->form[$this->action][$field] = $test;
31
        $this->form[$this->action][$field]['placeholder'] = (null !== $placeholder) ? $placeholder : $field;
32
	    return $this;
33
  	}
34
35
    public function getRules(string $action): Array
36
    {
37
		return (array_key_exists($action, $this->form)) ? $this->form[$action] : [];
38
	}
39
}
40