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

UserLanguage   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 3
eloc 18
c 2
b 0
f 1
dl 0
loc 39
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A makeIdentifierRequired() 0 9 2
A createValidator() 0 18 1
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