RoleValidator::setValidationRules()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 7
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 11
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Platine\App\Validator;
6
7
use Platine\App\Param\RoleParam;
8
use Platine\Framework\Form\Validator\AbstractValidator;
9
use Platine\Lang\Lang;
10
use Platine\Validator\Rule\MaxLength;
11
use Platine\Validator\Rule\MinLength;
12
use Platine\Validator\Rule\NotEmpty;
13
14
/**
15
* @class RoleValidator
16
* @package Platine\App\Validator
17
* @template TEntity as \Platine\Orm\Entity
18
*/
19
class RoleValidator extends AbstractValidator
20
{
21
    /**
22
    * Create new instance
23
    * @param RoleParam<TEntity> $param
24
    * @param Lang $lang
25
    */
26
    public function __construct(protected RoleParam $param, Lang $lang)
27
    {
28
        parent::__construct($lang);
29
    }
30
31
    /**
32
    * {@inheritdoc}
33
    */
34
    public function setValidationData(): void
35
    {
36
        $this->addData('name', $this->param->getName());
37
        $this->addData('description', $this->param->getDescription());
38
    }
39
40
    /**
41
    * {@inheritdoc}
42
    */
43
    public function setValidationRules(): void
44
    {
45
        $this->addRules('name', [
46
            new NotEmpty(),
47
            new MinLength(2),
48
            new MaxLength(50),
49
        ]);
50
51
        $this->addRules('description', [
52
            new MinLength(2),
53
            new MaxLength(150),
54
        ]);
55
    }
56
}
57