Passed
Push — master ( 1974d0...df0fbc )
by Peter
02:35
created

UserLanguage::createValidator()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
eloc 11
c 2
b 0
f 1
dl 0
loc 18
rs 9.9
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AbterPhp\Admin\Validation\Factory;
6
7
use AbterPhp\Framework\Http\Service\Execute\IRepoService;
8
use Opulence\Validation\Factories\ValidatorFactory;
9
use Opulence\Validation\IValidator;
10
11
class UserLanguage extends ValidatorFactory implements IConditional
12
{
13
    use ConditionalTrait;
14
15
    /**
16
     * @return IValidator
17
     */
18
    public function createValidator(): IValidator
19
    {
20
        $validator = parent::createValidator();
21
22
        $validator
23
            ->field('id')
24
            ->uuid();
25
26
        $validator
27
            ->field('identifier');
28
29
        $validator
30
            ->field('name')
31
            ->required();
32
33
        $this->makeIdentifierRequired($validator);
34
35
        return $validator;
36
    }
37
38
    /**
39
     * @param IValidator $validator
40
     */
41
    protected function makeIdentifierRequired(IValidator $validator): void
42
    {
43
        if ($this->additionalData !== IRepoService::CREATE) {
44
            return;
45
        }
46
47
        $validator
48
            ->field('identifier')
49
            ->required();
50
    }
51
}
52