IntlMessageFormatter::format()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 15
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3.0175

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 15
ccs 7
cts 8
cp 0.875
rs 10
c 0
b 0
f 0
cc 3
nc 3
nop 3
crap 3.0175
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Translator\Formatter\Intl;
6
7
use MessageFormatter;
8
use Yiisoft\Translator\MessageFormatterInterface;
9
10
final class IntlMessageFormatter implements MessageFormatterInterface
11
{
12
    /**
13
     * This method uses \MessageFormatter::format()
14
     *
15
     * @link https://php.net/manual/en/messageformatter.format.php
16
     */
17 34
    public function format(string $message, array $parameters, string $locale): string
18
    {
19 34
        if ($parameters === []) {
20 3
            return $message;
21
        }
22
23 31
        $formatter = new MessageFormatter($locale, $message);
24
25 31
        $result = $formatter->format($parameters);
26
27 31
        if ($result === false) {
28
            return $message;
29
        }
30
31 31
        return $result;
32
    }
33
}
34