Passed
Push — main ( 272bc9...03c64c )
by Andrey
09:28 queued 07:38
created

Replace   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 16
ccs 8
cts 8
cp 1
rs 10
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A toFormatArray() 0 9 2
A toFormat() 0 3 3
1
<?php
2
3
namespace Helldar\Support\Tools;
4
5
final class Replace
6
{
7 2
    public function toFormat(string $value, string $format = null): string
8
    {
9 2
        return empty($format) || $format === '%s' ? $value : sprintf($format, $value);
10
    }
11
12 20
    public function toFormatArray(array $values, string $format = null): array
13
    {
14 20
        if (empty($format)) {
15 20
            return $values;
16
        }
17
18 4
        return array_map(static function ($value) use ($format) {
19 4
            return sprintf($format, $value);
20 4
        }, $values);
21
    }
22
}
23