Passed
Branch MySQLBenchmark (e9fc1d)
by Gerben
03:22
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
    static function format(string $string, array $variables)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
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
}