Rules::action()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
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