Replace   A
last analyzed

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
 * This file is part of the "andrey-helldar/support" project.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 *
8
 * @author Andrey Helldar <[email protected]>
9
 *
10
 * @copyright 2021 Andrey Helldar
11
 *
12
 * @license MIT
13
 *
14
 * @see https://github.com/andrey-helldar/support
15
 */
16
17
namespace Helldar\Support\Tools;
18
19
class Replace
20
{
21 2
    public function toFormat(string $value, string $format = null): string
22
    {
23 2
        return empty($format) || $format === '%s' ? $value : sprintf($format, $value);
24
    }
25
26 24
    public function toFormatArray(array $values, string $format = null): array
27
    {
28 24
        if (empty($format)) {
29 24
            return $values;
30
        }
31
32 6
        return array_map(static function ($value) use ($format) {
33 6
            return sprintf($format, $value);
34 6
        }, $values);
35
    }
36
}
37