Replace::toFormat()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 1
c 1
b 0
f 0
nc 4
nop 2
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 3
rs 10
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