ArgumentsFormatter::expandArgument()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 4

Importance

Changes 0
Metric Value
cc 4
eloc 6
nc 3
nop 2
dl 0
loc 10
rs 9.2
c 0
b 0
f 0
ccs 6
cts 6
cp 1
crap 4
1
<?php
2
3
namespace DJStarCOM\NewRelic\Formatter;
4
5
class ArgumentsFormatter implements FormatterInterface
6
{
7
    /**
8
     * @param array $arguments
9
     * @return \ArrayObject
10
     */
11 11
    public function format(array $arguments)
12
    {
13 11
        $output = new \ArrayObject();
14 11
        foreach ($arguments as $key => $value) {
15 5
            if (null === $value || is_scalar($value)) {
16 2
                $output[$key] = $value;
17
            } else {
18 5
                $this->expandArgument($value, $output);
19
            }
20
        }
21
22 11
        return $output;
23
    }
24
25 4
    private function expandArgument($argument, &$flatten)
26
    {
27 4
        foreach ($argument as $key => $value) {
28 1
            if (null === $value || is_scalar($value)) {
29 1
                $flatten[$key] = $value;
30
            } else {
31 1
                $flatten[$key] = @json_encode($value);
32
            }
33
        }
34 4
    }
35
}
36