Passed
Pull Request — main (#96)
by Andrey
12:41
created

Replace::toFormatArray()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 5
c 1
b 0
f 0
nc 2
nop 2
dl 0
loc 9
rs 10
1
<?php
2
3
namespace Helldar\Support\Tools;
4
5
final class Replace
6
{
7
    public function toFormat(string $value, string $format = null): string
8
    {
9
        return empty($format) || $format === '%s' ? $value : sprintf($format, $value);
10
    }
11
12
    public function toFormatArray(array $values, string $format = null): array
13
    {
14
        if (empty($format)) {
15
            return $values;
16
        }
17
18
        return array_map(static function ($value) use ($format) {
19
            return sprintf($format, $value);
20
        }, $values);
21
    }
22
}
23