Passed
Pull Request — master (#1)
by Def
20:00 queued 05:04
created

SimpleMessageFormatter   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 11
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 6
c 1
b 0
f 0
dl 0
loc 11
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A format() 0 9 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
    public function format(string $message, array $parameters, string $locale): string
12
    {
13
        $replacements = [];
14
        foreach ($parameters as $key => $value) {
15
            if (is_scalar($value)) {
16
                $replacements['{' . $key . '}'] = $value;
17
            }
18
        }
19
        return strtr($message, $replacements);
20
    }
21
}
22