ArrayAttributeTranslator::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 0
nc 1
nop 1
dl 0
loc 3
rs 10
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Validator\AttributeTranslator;
6
7
use Yiisoft\Validator\AttributeTranslatorInterface;
8
9
/**
10
 * An attribute translator that uses array of translations.
11
 */
12
final class ArrayAttributeTranslator implements AttributeTranslatorInterface
13
{
14
    /**
15
     * @param array $translations Translations array where each key is an attribute name and the corresponding value is
16
     * a translation.
17
     *
18
     * @psalm-param array<string,string> $translations
19
     */
20
    public function __construct(
21
        private array $translations,
22
    ) {
23
    }
24
25
    public function translate(string $attribute): string
26
    {
27
        return $this->translations[$attribute] ?? $attribute;
28
    }
29
}
30