Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
Domain
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
3 / 3
5
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 file
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 owns
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
3
1<?php
2
3declare(strict_types=1);
4
5namespace Celemas\Verba\Tool;
6
7/**
8 * A translation domain: its catalog directory, the locales it maintains, and
9 * the scanners that discover its messages. The default domain also receives
10 * bare `__`/`__n` calls (those without an explicit domain).
11 *
12 * @api
13 */
14final class Domain
15{
16    /**
17     * @param list<string> $locales
18     * @param list<Scanner> $scanners
19     */
20    public function __construct(
21        public readonly string $name,
22        public readonly string $dir,
23        public readonly array $locales,
24        public readonly array $scanners,
25        public readonly bool $default = false,
26    ) {}
27
28    public function file(string $locale): string
29    {
30        return $this->dir . '/' . $this->name . '.' . $locale . '.php';
31    }
32
33    /**
34     * Whether a discovered message targeting $domain belongs here.
35     */
36    public function owns(?string $domain): bool
37    {
38        return $domain === $this->name || $this->default && $domain === null;
39    }
40}