EnumTransformation   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 6
c 1
b 0
f 0
dl 0
loc 17
ccs 5
cts 5
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A apply() 0 7 4
1
<?php
2
3
namespace Cerbero\Transformer\Transformations;
4
5
/**
6
 * Transform a value into an enum.
7
 *
8
 */
9
class EnumTransformation extends AbstractTransformation
10
{
11
    const DELIMITER = '=';
12
13
    /**
14
     * Apply the transformation
15
     *
16
     * @param array $parameters
17
     * @return mixed
18
     */
19 3
    public function apply(array $parameters)
20
    {
21 3
        foreach ($parameters as $parameter) {
22 3
            list($actual, $transformed) = explode(static::DELIMITER, $parameter);
23
            // die(var_dump($this->value, $actual, $transformed));
24 3
            if ($this->value == $actual) {
25 3
                return is_numeric($transformed) ? (int)$transformed : $transformed;
26
            }
27
        }
28 3
    }
29
}
30