GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

KeyValueTranslator::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 6
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Marcosh\PhpValidationDSL\Translator;
6
7
use Webmozart\Assert\Assert;
8
use function array_key_exists;
9
10
final class KeyValueTranslator implements Translator
11
{
12
    /**
13
     * @var array key value dictionary of translations
14
     */
15
    private $dictionary;
16
17
    private function __construct(array $dictionary)
18
    {
19
        Assert::allString(array_keys($dictionary));
20
        Assert::allString($dictionary);
21
22
        $this->dictionary = $dictionary;
23
    }
24
25
    public static function withDictionary(array $dictionary): self
26
    {
27
        return new self($dictionary);
28
    }
29
30
    public function translate(string $string): string
31
    {
32
        return array_key_exists($string, $this->dictionary) ?
33
            $this->dictionary[$string] :
34
            $string;
35
    }
36
}
37