Passed
Push — master ( 86cfdb...e29dd4 )
by nguereza
03:59 queued 01:47
created

RoleValidator::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 4
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
    * The parameter instance
23
    * @var RoleParam<TEntity>
24
    */
25
    protected RoleParam $param;
26
27
    /**
28
    * Create new instance
29
    * @param RoleParam<TEntity> $param
30
    * @param Lang $lang
31
    */
32
    public function __construct(RoleParam $param, Lang $lang)
33
    {
34
        parent::__construct($lang);
35
        $this->param = $param;
36
    }
37
38
    /**
39
    * {@inheritdoc}
40
    */
41
    public function setValidationData(): void
42
    {
43
        $this->addData('name', $this->param->getName());
44
        $this->addData('description', $this->param->getDescription());
45
    }
46
47
    /**
48
    * {@inheritdoc}
49
    */
50
    public function setValidationRules(): void
51
    {
52
        $this->addRules('name', [
53
            new NotEmpty(),
54
            new MinLength(2),
55
            new MaxLength(50),
56
        ]);
57
58
        $this->addRules('description', [
59
            new MinLength(2),
60
            new MaxLength(150),
61
        ]);
62
    }
63
}
64