Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
83.33% covered (warning)
83.33%
5 / 6
66.67% covered (warning)
66.67%
2 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
Locale
83.33% covered (warning)
83.33%
5 / 6
66.67% covered (warning)
66.67%
2 / 3
6.17
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
3
 fallback
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
2
 domain
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3declare(strict_types=1);
4
5namespace Cosray;
6
7class Locale
8{
9    public readonly string $urlPrefix;
10    public readonly array $domains;
11
12    public function __construct(
13        protected readonly Locales $locales,
14        public readonly string $id,
15        public readonly string $title,
16        public readonly ?string $fallback = null,
17        public readonly ?string $pgDict = null,
18        ?array $domains = null,
19        ?string $urlPrefix = null,
20    ) {
21        if ($domains) {
22            $this->domains = array_map(static fn($d) => strtolower($d), $domains);
23        } else {
24            $this->domains = [];
25        }
26
27        $this->urlPrefix = $urlPrefix ?: $id;
28    }
29
30    /**
31     * The fallback locale is only used for content translations
32     * stored in the database. Translations provided by gettext
33     * e. g. in templates or source code do not work with fallback.
34     */
35    public function fallback(): ?Locale
36    {
37        return $this->fallback ? $this->locales->get($this->fallback) : null;
38    }
39
40    public function domain(int $index = 0): string
41    {
42        return $this->domains[$index];
43    }
44}