Conditions | 7 |
Paths | 7 |
Total Lines | 31 |
Code Lines | 15 |
Lines | 5 |
Ratio | 16.13 % |
Tests | 16 |
CRAP Score | 7 |
Changes | 0 |
1 | <?php |
||
63 | 36 | public function transform($value) |
|
64 | { |
||
65 | // only transform when we have something to transform |
||
66 | 36 | if (is_null($value)) { |
|
67 | 2 | return $value; |
|
68 | } |
||
69 | |||
70 | 34 | if (is_bool($value)) { |
|
71 | 4 | return $value; |
|
72 | } |
||
73 | |||
74 | 30 | View Code Duplication | if (!is_scalar($value)) { |
|
|||
75 | 2 | throw new TransformationFailedException( |
|
76 | 2 | sprintf('Expected a scalar value to transform, got %s instead.', var_export($value, true)) |
|
77 | 2 | ); |
|
78 | } |
||
79 | |||
80 | 28 | if (trim($value) === '') { |
|
81 | 2 | return null; |
|
82 | } |
||
83 | |||
84 | 26 | if (in_array(mb_strtolower($value), $this->truthyValues)) { |
|
85 | 8 | return true; |
|
86 | } |
||
87 | |||
88 | 18 | if (in_array(mb_strtolower($value), $this->falsyValues)) { |
|
89 | 8 | return false; |
|
90 | } |
||
91 | |||
92 | 10 | return (boolean) $value; |
|
93 | } |
||
94 | } |
||
95 |
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.