Completed
Push — master ( 039dcf...417ea8 )
by Maik
03:08
created

Interpolator   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 0
dl 0
loc 26
ccs 6
cts 6
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A interpolate() 0 12 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