format()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 3

Importance

Changes 5
Bugs 0 Features 1
Metric Value
cc 3
eloc 7
c 5
b 0
f 1
nc 4
nop 2
dl 0
loc 13
ccs 8
cts 8
cp 1
crap 3
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
use MichaelRubel\EnhancedContainer\Call;
6
use MichaelRubel\Formatters\FormatterService;
7
8
if (! function_exists('format')) {
9
    /**
10
     * @param  string  $formatter
11
     * @param  mixed  $items
12
     *
13
     * @return mixed
14
     */
15
    function format(string $formatter, mixed ...$items): mixed
16
    {
17 75
        $items = FormatterService::unwrapIfArray($items);
18
19 75
        $formatter = class_exists($formatter) || interface_exists($formatter)
20 53
            ? call($formatter, $items)
21 24
            : call($formatter . FormatterService::BINDING_POSTFIX, $items);
22
23 73
        FormatterService::ensureFormatterImplementsInterface(
24 73
            $formatter->getInternal(Call::INSTANCE)
25 73
        );
26
27 71
        return $formatter->format();
28
    }
29
}
30