IntlMessageFormatter   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Test Coverage

Coverage 87.5%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 8
c 1
b 0
f 0
dl 0
loc 22
ccs 7
cts 8
cp 0.875
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A format() 0 15 3
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