ArgumentFormatter::format()   B
last analyzed

Complexity

Conditions 8
Paths 6

Size

Total Lines 24

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 16
CRAP Score 8

Importance

Changes 0
Metric Value
dl 0
loc 24
ccs 16
cts 16
cp 1
rs 8.4444
c 0
b 0
f 0
cc 8
nc 6
nop 2
crap 8
1
<?php
2
3
/**
4
 * This file is part of Collision.
5
 *
6
 * (c) Nuno Maduro <[email protected]>
7
 *
8
 *  For the full copyright and license information, please view the LICENSE
9
 *  file that was distributed with this source code.
10
 */
11
12
namespace NunoMaduro\Collision;
13
14
use NunoMaduro\Collision\Contracts\ArgumentFormatter as ArgumentFormatterContract;
15
16
/**
17
 * This is an Collision Argument Formatter implementation.
18
 *
19
 * @author Nuno Maduro <[email protected]>
20
 */
21
class ArgumentFormatter implements ArgumentFormatterContract
22
{
23
    /**
24
     * {@inheritdoc}
25
     */
26 6
    public function format(array $arguments, bool $recursive = true): string
27
    {
28 6
        $result = [];
29
30 6
        foreach ($arguments as $argument) {
31
            switch (true) {
32 4
                case is_string($argument):
33 2
                    $result[] = '"' . $argument . '"';
34 2
                    break;
35 3
                case is_array($argument):
36 2
                    $associative = array_keys($argument) !== range(0, count($argument) - 1);
37 2
                    if ($recursive && $associative && count($argument) <= 5) {
38 1
                        $result[] = '[' . $this->format($argument, false) . ']';
39
                    }
40 2
                    break;
41 2
                case is_object($argument):
42 2
                    $class    = get_class($argument);
43 2
                    $result[] = "Object($class)";
44 4
                    break;
45
            }
46
        }
47
48 6
        return implode(', ', $result);
49
    }
50
}
51