StripCommentsTransformer::transform()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 5
cts 5
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 3
nc 2
nop 1
crap 2
1
<?php
2
3
namespace TreeHouse\Feeder\Modifier\Item\Transformer;
4
5
use Symfony\Component\HttpFoundation\ParameterBag;
6
7
class StripCommentsTransformer implements TransformerInterface
8
{
9 4
    public function transform(ParameterBag $item)
10
    {
11 4
        foreach ($item->all() as $key => $value) {
12 4
            $item->set($key, $this->transformRecursive($value));
13 4
        }
14 4
    }
15
16
    /**
17
     * @param mixed $value
18
     *
19
     * @return mixed
20
     */
21 4
    protected function transformRecursive($value)
22
    {
23 4
        if (is_array($value)) {
24 4
            if (array_key_exists('#comment', $value)) {
25 4
                unset($value['#comment']);
26 4
            }
27
28 4
            foreach ($value as &$subvalue) {
29 2
                $subvalue = $this->transformRecursive($subvalue);
30 4
            }
31 4
        }
32
33 4
        return $value;
34
    }
35
}
36