Passed
Push — master ( 782dea...729c40 )
by Gerben
06:59 queued 02:14
created

Utility   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 20
rs 10
c 0
b 0
f 0
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A format() 0 11 1
1
<?php
2
3
4
namespace Hyperized\Benchmark\Generic;
5
6
7
class Utility
8
{
9
    /**
10
     * @param string $string
11
     * @param array $variables
12
     *
13
     * https://stackoverflow.com/a/17372566/1757763
14
     * @return mixed
15
     */
16
    public static function format(string $string, array $variables)
17
    {
18
        $string = \preg_replace_callback('#\{\}#', function () {
19
            static $i = 0;
20
            return '{' . ($i++) . '}';
21
        }, $string);
22
23
        return \str_replace(
24
            \array_map(function ($k) {
25
                return '{' . $k . '}';
26
            }, \array_keys($variables)), \array_values($variables), $string
27
        );
28
    }
29
}