SimpleForm::getAttributeLabels()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 5
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Validator\Tests\Support\Data;
6
7
use Yiisoft\Validator\AttributeTranslator\ArrayAttributeTranslator;
8
use Yiisoft\Validator\AttributeTranslatorInterface;
9
use Yiisoft\Validator\AttributeTranslatorProviderInterface;
10
use Yiisoft\Validator\Rule\Email;
11
use Yiisoft\Validator\Rule\Length;
12
use Yiisoft\Validator\RulesProviderInterface;
13
14
final class SimpleForm implements RulesProviderInterface, AttributeTranslatorProviderInterface
15
{
16
    public function __construct(
17
        public string $name = '',
18
        public string $mail = '',
19
    ) {
20
    }
21
22
    /**
23
     * @psalm-return array<string, string>
24
     */
25
    public function getAttributeLabels(): array
26
    {
27
        return [
28
            'name' => 'Имя',
29
            'mail' => 'Почта',
30
        ];
31
    }
32
33
    public function getAttributeTranslator(): ?AttributeTranslatorInterface
34
    {
35
        return new ArrayAttributeTranslator($this->getAttributeLabels());
36
    }
37
38
    public function getRules(): array
39
    {
40
        return [
41
            'name' => [
42
                new Length(min: 8, lessThanMinMessage: '{attribute} плохое.'),
43
            ],
44
            'mail' => [
45
                new Email(),
46
            ],
47
        ];
48
    }
49
}
50