AuthValidator   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
c 1
b 0
f 0
dl 0
loc 44
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A setValidationRules() 0 13 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\AuthParam;
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 AuthValidator
17
* @package Platine\App\Validator
18
* @template TEntity as \Platine\Orm\Entity
19
*/
20
class AuthValidator extends AbstractValidator
21
{
22
    /**
23
    * The parameter instance
24
    * @var AuthParam<TEntity>
25
    */
26
    protected AuthParam $param;
27
28
    /**
29
    * Create new instance
30
    * @param AuthParam<TEntity> $param
31
    * @param Lang $lang
32
    */
33
    public function __construct(AuthParam $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('username', $this->param->getUsername());
45
        $this->addData('password', $this->param->getPassword());
46
    }
47
48
    /**
49
    * {@inheritdoc}
50
    */
51
    public function setValidationRules(): void
52
    {
53
        $this->addRules('username', [
54
            new NotEmpty(),
55
            new MinLength(2),
56
            new MaxLength(20),
57
            new AlphaNumericDash(),
58
        ]);
59
60
        $this->addRules('password', [
61
            new NotEmpty(),
62
            new MinLength(5),
63
            new MaxLength(100),
64
        ]);
65
    }
66
}
67