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

Utility::format()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 8
nc 1
nop 2
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
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
}