I18n   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 19
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 2
A getText() 0 5 2
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