EnumTransformation::apply()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
c 1
b 0
f 0
dl 0
loc 7
ccs 5
cts 5
cp 1
rs 10
cc 4
nc 4
nop 1
crap 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