I18n::getText()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 1
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
namespace html_go\i18n;
3
4
final class I18n
5
{
6
    /**
7
     * @var array<string, string>
8
     */
9
    private array $bundle = [];
10
11
    public function __construct(string $bundlePath) {
12
        if (!\file_exists($bundlePath)) {
13
            throw new \InvalidArgumentException("i18n bundle file not found [$bundlePath]");
14
        }
15
        $this->bundle = include $bundlePath;
16
    }
17
18
    public function getText(string $key): string {
19
        if (\array_key_exists($key, $this->bundle)) {
20
            return $this->bundle[$key];
21
        }
22
        return '!'.$key.'!';
23
    }
24
}
25