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

PermissionValidator   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setValidationRules() 0 18 1
A __construct() 0 4 1
A setValidationData() 0 5 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
    * The parameter instance
24
    * @var PermissionParam<TEntity>
25
    */
26
    protected PermissionParam $param;
27
28
    /**
29
    * Create new instance
30
    * @param PermissionParam<TEntity> $param
31
    * @param Lang $lang
32
    */
33
    public function __construct(PermissionParam $param, Lang $lang)
34
    {
35
        parent::__construct($lang);
36
        $this->param = $param;
37
    }
38
39
    /**
40
    * {@inheritdoc}
41
    */
42
    public function setValidationData(): void
43
    {
44
        $this->addData('code', $this->param->getCode());
45
        $this->addData('description', $this->param->getDescription());
46
        $this->addData('depend', $this->param->getDepend());
47
    }
48
49
    /**
50
    * {@inheritdoc}
51
    */
52
    public function setValidationRules(): void
53
    {
54
        $this->addRules('code', [
55
            new NotEmpty(),
56
            new MinLength(2),
57
            new MaxLength(20),
58
            new AlphaNumericDash(),
59
        ]);
60
61
        $this->addRules('description', [
62
            new NotEmpty(),
63
            new MinLength(2),
64
            new MaxLength(100),
65
        ]);
66
67
        $this->addRules('depend', [
68
            new MinLength(2),
69
            new MaxLength(20),
70
        ]);
71
    }
72
}
73