Passed
Pull Request — master (#451)
by Sergei
04:05 queued 01:34
created

ArrayAttributeTranslator   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 13
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A translate() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Validator\AttributeTranslator;
6
7
use Yiisoft\Validator\AttributeTranslatorInterface;
8
9
/**
10
 * An attributes translator that used array of translations for translate attribute name.
11
 */
12
final class ArrayAttributeTranslator implements AttributeTranslatorInterface
13
{
14
    public function __construct(
15
        /**
16
         * @var array<string,string>
17
         */
18
        private array $translations,
19
    ) {
20
    }
21
22
    public function translate(string $attribute): string
23
    {
24
        return $this->translations[$attribute] ?? $attribute;
25
    }
26
}
27