Passed
Pull Request — master (#97)
by Alexander
02:08
created

ValidatorFactory::normalizeRule()   A

Complexity

Conditions 6
Paths 18

Size

Total Lines 25
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 6.1308

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 6
c 1
b 0
f 0
dl 0
loc 25
rs 9.2222
eloc 12
nc 18
nop 1
ccs 11
cts 13
cp 0.8462
crap 6.1308
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Validator;
6
7
use Yiisoft\Translator\TranslatorInterface;
8
9
final class ValidatorFactory implements ValidatorFactoryInterface
10
{
11
    private ?TranslatorInterface $translator;
12
    private ?string $translationDomain;
13
    private ?string $translationLocale;
14
15 1
    public function __construct(
16
        TranslatorInterface $translator = null,
17
        string $translationDomain = null,
18
        string $translationLocale = null
19
    ) {
20 1
        $this->translator = $translator;
21 1
        $this->translationDomain = $translationDomain;
22 1
        $this->translationLocale = $translationLocale;
23 1
    }
24
25 1
    public function create(): ValidatorInterface
26
    {
27 1
        $validator = new Validator();
28
29 1
        if ($this->translator !== null) {
30
            $validator = $validator->withTranslator($this->translator);
31
        }
32
33 1
        if ($this->translationDomain !== null) {
34
            $validator = $validator->translationDomain($this->translationDomain);
0 ignored issues
show
Bug introduced by
The method translationDomain() does not exist on Yiisoft\Validator\Validator. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

34
            /** @scrutinizer ignore-call */ 
35
            $validator = $validator->translationDomain($this->translationDomain);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
35
        }
36
37 1
        if ($this->translationLocale !== null) {
38
            $validator = $validator->translationLocale($this->translationLocale);
39
        }
40
41 1
        return $validator;
42
    }
43
}
44