Interpolator::interpolate()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 12
ccs 6
cts 6
cp 1
rs 9.8666
c 0
b 0
f 0
cc 3
nc 2
nop 2
crap 3
1
<?php
2
3
/**
4
 * This file is part of the PHP Generics package.
5
 *
6
 * @package Generics
7
 */
8
namespace Generics\Util;
9
10
/**
11
 *
12
 * @author Maik Greubel <[email protected]>
13
 */
14
trait Interpolator
15
{
16
17
    /**
18
     * Interpolates context values into the message placeholders.
19
     *
20
     * @param string $message
21
     *            The message containing placeholders
22
     * @param array $context
23
     *            The context array containing the replacers
24
     *
25
     * @return string The interpolated message
26
     */
27 70
    private static function interpolate($message, array $context = array()): string
28
    {
29 70
        $replace = array();
30
        
31 70
        if ($context !== null) {
32 70
            foreach ($context as $key => $val) {
33 55
                $replace['{' . $key . '}'] = $val;
34
            }
35
        }
36
        
37 70
        return strtr($message, $replace);
38
    }
39
}
40