PermissionValidator   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 13
c 2
b 0
f 0
dl 0
loc 37
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setValidationRules() 0 13 1
A __construct() 0 3 1
A setValidationData() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Platine\App\Validator;
6
7
use Platine\App\Param\PermissionParam;
8
use Platine\Framework\Form\Validator\AbstractValidator;
9
use Platine\Lang\Lang;
10
use Platine\Validator\Rule\AlphaNumericDash;
11
use Platine\Validator\Rule\MaxLength;
12
use Platine\Validator\Rule\MinLength;
13
use Platine\Validator\Rule\NotEmpty;
14
15
/**
16
* @class PermissionValidator
17
* @package Platine\App\Validator
18
* @template TEntity as \Platine\Orm\Entity
19
*/
20
class PermissionValidator extends AbstractValidator
21
{
22
    /**
23
    * Create new instance
24
    * @param PermissionParam<TEntity> $param
25
    * @param Lang $lang
26
    */
27
    public function __construct(protected PermissionParam $param, Lang $lang)
28
    {
29
        parent::__construct($lang);
30
    }
31
32
    /**
33
    * {@inheritdoc}
34
    */
35
    public function setValidationData(): void
36
    {
37
        $this->addData('code', $this->param->getCode());
38
        $this->addData('description', $this->param->getDescription());
39
    }
40
41
    /**
42
    * {@inheritdoc}
43
    */
44
    public function setValidationRules(): void
45
    {
46
        $this->addRules('code', [
47
            new NotEmpty(),
48
            new MinLength(2),
49
            new MaxLength(20),
50
            new AlphaNumericDash(),
51
        ]);
52
53
        $this->addRules('description', [
54
            new NotEmpty(),
55
            new MinLength(2),
56
            new MaxLength(100),
57
        ]);
58
    }
59
}
60