SimpleMessageFormatter::format()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 5
c 2
b 0
f 0
dl 0
loc 10
ccs 6
cts 6
cp 1
rs 10
cc 3
nc 3
nop 3
crap 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Translator\Formatter\Simple;
6
7
use Yiisoft\Translator\MessageFormatterInterface;
8
9
class SimpleMessageFormatter implements MessageFormatterInterface
10
{
11 3
    public function format(string $message, array $parameters, string $locale): string
12
    {
13 3
        $replacements = [];
14
        /** @var mixed $value */
15 3
        foreach ($parameters as $key => $value) {
16 3
            if (is_scalar($value)) {
17 2
                $replacements['{' . $key . '}'] = $value;
18
            }
19
        }
20 3
        return strtr($message, $replacements);
21
    }
22
}
23