NormalizedStringTransformer::transform()   A
last analyzed

Complexity

Conditions 4
Paths 5

Size

Total Lines 19

Duplication

Lines 19
Ratio 100 %

Code Coverage

Tests 6
CRAP Score 4.5923

Importance

Changes 0
Metric Value
dl 19
loc 19
ccs 6
cts 9
cp 0.6667
rs 9.6333
c 0
b 0
f 0
cc 4
nc 5
nop 1
crap 4.5923
1
<?php
2
3
namespace TreeHouse\IoBundle\Item\Modifier\Data\Transformer;
4
5
use TreeHouse\Feeder\Exception\TransformationFailedException;
6
use TreeHouse\Feeder\Modifier\Data\Transformer\TransformerInterface;
7
8
/**
9
 * Normalizes an input to be a guaranteed string.
10
 */
11 View Code Duplication
class NormalizedStringTransformer 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...
12
{
13 4
    public function transform($value)
14
    {
15 4
        if (is_null($value)) {
16
            return $value;
17
        }
18
19 4
        if (is_scalar($value)) {
20 4
            $value = (string) $value;
21
        }
22
23 4
        if (!is_string($value)) {
24
            throw new TransformationFailedException(
25
                sprintf('Expected a string to transform, got %s instead', json_encode($value))
26
            );
27
        }
28
29
        // strip tags just to be sure
30 4
        return trim(strip_tags($value));
31
    }
32
}
33