DefaultValidatorTranslator::trans()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 2
crap 2
1
<?php declare(strict_types=1);
2
/**
3
 * Validation.
4
 *
5
 * @copyright Copyright (c) 2016 Starweb AB
6
 * @license   BSD 3-Clause
7
 */
8
9
namespace Starlit\Validation;
10
11
class DefaultValidatorTranslator implements ValidatorTranslatorInterface
12
{
13
    /**
14
     * @var array
15
     */
16
    protected $texts = [
17
        'errorTheNoneSpecifiedField' => 'Field',
18
        'errorFieldXIsRequired' => '%field% must be filled in.',
19
        'errorFieldMustBeMinNumber' => '%field% must be minimum %number%.',
20
        'errorFieldMustBeMaxNumber' => '%field% must be maximum %number%.',
21
        'errorFieldMustBeMinXLength' => '%field% must include minimum %numberOf% characters.',
22
        'errorFieldMustBeMaxXLength' => '%field% must include maximum %numberOf% characters.',
23
        'errorFieldMustBeXLength' => '%field% must consist of %numberOf% characters.',
24
        'errorFieldInvalidFormat' => '%field% has invalid format.',
25
        'errorFieldValidCharactersAreX' => 'Valid characters are %characters%.',
26
        'errorInvalidEmail' => 'Email address is invalid.',
27
        'errorInvalidDate' => 'Date is invalid.',
28
        'errorInvalidDateTime' => 'Date/time is invalid.',
29
    ];
30
31
    /**
32
     * {@inheritdoc}
33
     */
34 40
    public function trans(string $id, array $parameters = []): string
35
    {
36 40
        if (isset($this->texts[$id])) {
37 39
            return strtr($this->texts[$id], $parameters);
38
        }
39
40 1
        return $id;
41
    }
42
}
43