Utility::format()   A
last analyzed

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 10
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
     * @return mixed
14
     *
15
     * Sourced: https://stackoverflow.com/a/17372566/1757763
16
     */
17
    public static function format(string $string, array $variables)
18
    {
19
        $string = \preg_replace_callback('#\{\}#', function () {
20
            static $i = 0;
21
            return '{' . ($i++) . '}';
22
        }, $string);
23
24
        return \str_replace(
25
            \array_map(function ($k) {
26
                return '{' . $k . '}';
27
            }, \array_keys($variables)), \array_values($variables), $string
28
        );
29
    }
30
}