Test Failed
Push — develop ( 64b6b0...ddb817 )
by nguereza
02:24
created

UserValidator::setRules()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 27
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 17
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 27
rs 9.7
1
<?php
2
3
namespace Platine\Framework\Demo\Form\Validator;
4
5
use Platine\Framework\Demo\Form\Param\UserParam;
6
use Platine\Validator\Rule\Max;
7
use Platine\Validator\Rule\Min;
8
use Platine\Validator\Rule\MinLength;
9
use Platine\Validator\Rule\NotEmpty;
10
use Platine\Validator\Rule\Number;
11
use Platine\Validator\Validator;
12
13
class UserValidator extends AbstractValidator
14
{
15
16
    protected UserParam $param;
17
18
    /**
19
     * Create new instance
20
     * @param UserParam $param
21
     * @param Validator|null $validator
22
     */
23
    public function __construct(UserParam $param, ?Validator $validator = null)
24
    {
25
        parent::__construct($validator);
26
        $this->param = $param;
27
    }
28
29
    public function setData(): void
30
    {
31
        $this->addData('username', $this->param->getUsername());
32
        $this->addData('lastname', $this->param->getLastname());
33
        $this->addData('firstname', $this->param->getFirstname());
34
        $this->addData('age', $this->param->getAge());
35
        $this->addData('password', $this->param->getPassword());
36
    }
37
38
    public function setRules(): void
39
    {
40
        $this->validator->addRules('username', [
41
           new NotEmpty(),
42
           new MinLength(3)
43
        ]);
44
45
        $this->validator->addRules('lastname', [
46
           new NotEmpty(),
47
           new MinLength(3)
48
        ]);
49
50
        $this->validator->addRules('firstname', [
51
           new NotEmpty(),
52
           new MinLength(3)
53
        ]);
54
55
        $this->validator->addRules('age', [
56
           new NotEmpty(),
57
           new Number(),
58
           new Min(0),
59
           new Max(100),
60
        ]);
61
62
        $this->validator->addRules('password', [
63
           new NotEmpty(),
64
           new MinLength(5),
65
        ]);
66
    }
67
}
68