Passed
Push — master ( 42c6c4...6eb781 )
by Henri
06:37
created

Rules::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
3
namespace HnrAzevedo\Validator;
4
5
Class Rules
6
{
7
    use Helper;
8
9
    private string $action;
10
11
    private array $form = array();
12
13
    public function __construct(object $model)
14
    {
15
	    $this->form['model'] = ucfirst(get_class($model));
16
	}
17
18
    public function action(string $action): Rules
19
    {
20
	    $this->action = $action;
21
	    return $this;
22
	}
23
24
    public function field(string $field, array $test, ?string $placeholder = null): Rules
25
    {
26
	    if(empty($this->action)){
27
            self::$errors[] = self::$err['nFoundForm'];
28
            return $this;
29
        }
30
31
        $this->form[$this->action][$field] = $test;
32
        $this->form[$this->action][$field]['placeholder'] = (null !== $placeholder) ? $placeholder : $test;
33
	    return $this;
34
  	}
35
36
    public function getRules(string $action): Array
37
    {
38
		return (array_key_exists($action, $this->form)) ? $this->form[$action] : [];
39
	}
40
}
41