Passed
Branch MySQLBenchmark (e9fc1d)
by Gerben
03:22
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
    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
}