Completed
Pull Request — 2.x (#27)
by
unknown
02:09
created

BasicFormatter   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 5
Bugs 0 Features 0
Metric Value
wmc 3
c 5
b 0
f 0
lcom 0
cbo 0
dl 0
loc 28
ccs 9
cts 9
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A format() 0 12 3
1
<?php
2
/**
3
 *
4
 * This file is part of the Aura Project for PHP.
5
 *
6
 * @package Aura.Intl
7
 *
8
 * @license http://opensource.org/licenses/MIT MIT
9
 *
10
 */
11
namespace Aura\Intl;
12
13
/**
14
 *
15
 * BasicFormatter
16
 *
17
 * @package Aura.Intl
18
 *
19
 */
20
class BasicFormatter implements FormatterInterface
21
{
22
    /**
23
     *
24
     * Format message
25
     *
26
     * @param string $locale
27
     *
28
     * @param string $string
29
     *
30
     * @param array $tokens_values
31
     *
32
     * @return string A string replaced with the token values
33
     *
34
     */
35 1
    public function format($locale, $string, array $tokens_values)
36
    {
37 1
        $replace = [];
38 1
        foreach ($tokens_values as $token => $value) {
39
            // convert an array to a CSV string
40 1
            if (is_array($value)) {
41 1
                $value = '"' . implode('", "', $value) . '"';
42 1
            }
43 1
            $replace['{' . $token . '}'] = $value;
44 1
        }
45 1
        return strtr($string, $replace);
46
    }
47
}
48