RemoveFieldsTransformer::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 4
Ratio 100 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 4
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
namespace TreeHouse\Feeder\Modifier\Item\Transformer;
4
5
use Symfony\Component\HttpFoundation\ParameterBag;
6
7
/**
8
 * Filters out unwanted fields.
9
 */
10 View Code Duplication
class RemoveFieldsTransformer implements TransformerInterface
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
11
{
12
    /**
13
     * @var array
14
     */
15
    protected $fields;
16
17
    /**
18
     * @param array $fields The fields to remove
19
     */
20 2
    public function __construct(array $fields)
21
    {
22 2
        $this->fields = $fields;
23 2
    }
24
25
    /**
26
     * @inheritdoc
27
     */
28 2
    public function transform(ParameterBag $item)
29
    {
30 2
        foreach ($item->keys() as $key) {
31 2
            if (in_array($key, $this->fields)) {
32 2
                $item->remove($key);
33 2
            }
34 2
        }
35 2
    }
36
}
37